Re: Reflection - When to use?
- From: "Joanna Carter [TeamB]" <joanna@xxxxxxxxxxxx>
- Date: Sat, 16 Sep 2006 21:49:05 +0100
"heddy" <hedbonker@xxxxxxxxx> a écrit dans le message de news:
1158438496.786252.154430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|I understand that reflection allows me to discover the metadata of a
| class at runtime (properties, methods etc). What I don't understand is
| where this is useful. For example:
|
| If I am the sole author of an application, I already know the metadata
| about my classes - I wrote them. And even if I did not - Let's say I
| buy a 3rd party class lib, it will be documented for me with that lib.
|
| If I am part of a dev team, the same is true - If I use a class that I
| did not author, I should still be able to reference the documentation
| for that class and use it.
|
| Can someone clarify for me?
For example, I write many different business classes, and I need to store
instance of these classes in a mechanism that hides the database and
translates those objects into SQL commands.
I write a storage mechanism with methods like this :
class Storage
{
void StoreObject(object obj)
{
PropertyInfo[] properties = obj.GetType().GetProperties();
// read properties and their values
// and create SQL Update or Insert statements
// using the names and values found.
}
...
}
and many other situations where the type of an object could be one of many.
However, reflection is not always necessary for these kind of tasks as the
Visitor design pattern can do this kind of thing
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
.
- References:
- Reflection - When to use?
- From: heddy
- Reflection - When to use?
- Prev by Date: Re: VB to C#
- Next by Date: Reduce application working set.
- Previous by thread: Reflection - When to use?
- Next by thread: Re: Reflection - When to use?
- Index(es):
Relevant Pages
|