Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do this in .NET
Message
De
19/04/2005 09:47:00
 
 
À
19/04/2005 04:09:54
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01004810
Message ID:
01006163
Vues:
28
You know what, Walter? This is has been a very good discussion, but I think that we're going to have to agree to disagree here. I like Interfaces and I think they're a quite powerful addition to any language. Where the use of Reflection is a better choice, IMHO, is where accessing the property or calling the method is not something that is needed all the time. Then it's probably not worth creating an Interface for the occasional use. Anyway, that's just my opinion. Yours is different and that's ok. =)

~~Bonnie



>Hi bonnie,
>
>>>>Well though the above does not look real pretty, from an architectual view I like this better. Writing such functionality now is independed from the implementation of the classes, hence my favour the above. <
>>
>>Well, I guess we'll have to agree to disagree, although I still think you're missing the point of an interface. There is no additional functionality implemented in the classes. You already want to have a SetFilter() method or a SetFocusAtAdd property in your classes, so you're not adding any functionality at all to those classes that need that method or that property. All you're doing is setting up the class definition to implement one or more interfaces.
>>
>>As an example, you could have an ISetFocus interface (that stipulates that the class contain a SetFocusAtAdd property), and a IFilter interface (that stipulates that the class contains a SetFilter() method). You'd only implement these interfaces on the classes that you need to.
>
>
>Lets see if I get this right. Are you saying you want to add an interface which basically does not have anything in it, except one property, just for the use of using this interface in order to solve the problem of the orginal question ?
>
>Lets see, what this means in practise. Since interfaces only contain the definitions of properties, events and methods, you'll have to define the implementation in the class. This is very similar to adding the methods, events and properties in the subclass itself without the implementation of interfaces.
>
>Though I can see that you can do typesave functions on objects having the interface implemented, this does not apply to the function described in the orginal message. Since the parameter of the function is of type object and thus can receive any object, you'll have to explicitely check if the object has the ISetFocus interface implemented.
>
>I wonder how much different is this from checking if the object has a particular method or property implemented ?? The problem I've got with Interfaces is that whenever you introduce new functionality simular to the original, you need to create and implement a new interface just for the aid of the new functionality. And what does it offer ?? Net result is that you create type safety at compile time in the algorithm (if you cast the object into ISetFocus), but that is about all.
>
>There are quite a few pitfalls with using interfaces this way. What do you do when you want to access already existing methods or properties already defined by its baseclass or subclass. Can you override them with interfaces. If so, is this wise to do ?? If, so you'll have to walk through the all the classes to add the interface. You'll have to keep your interfaces very granular in order to retain flexibility and avoid situations that two interfaces more or less define the same methods, events and properties.
>
>The solution you provided with reflection does not care at all of how a property or method is implemented just as long as it is implemented without the developer having to deal with the initial design of all interfaces an questioning how this was implemented. You gain flexibility when when the parameter or method to call is provided by a parameter.
>
>My conclusions is that reflection offers me a solution that is highly reusable and does not break on any circumstance. It does not care of how methods or properties have been defined on the object, as long as it is there. I don't care that much about type safety. Many years of experience with VFP will make that I can live with that :)
>
>Walter,
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform