Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why Use Interfaces
Message
De
03/01/2008 23:19:30
 
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01278205
Message ID:
01279396
Vues:
23
I think it's different in this case. Have you ever seen a dotnet class that implements several interfaces? Or inherits from a class and implements an interface or 2?

It has the possibility to make your app more robust and cleaner. For example you can define an interface that has some basic methods to deal with business classes. Just for grins it might have some basic save methods for backing up the data before your changes are made. Which can be used across multiple classes that have no real relationship. You will do the same algorithm for saving the data no matter what type of class it is.

If you have an employee class, this can inherit from your base person class, and implement your interface with the basic save, etc., methods. You might have a job class, that inherits from another base class, but also implements the same interface.

Because both classes implement the same interface, you are assured that no matter what the class is, you call the same methods to save.

That's why you see interfaces such as ISerializable, ICloneable, etc. Use Interfaces for functions that will operate across disaparate classes.

Use base classes to implement class functionality particular to that class, but interfaces to help define basic class functionality. Makes for a much more readable program.



>>>>... Interfaces can be used to simulate multiple-inheritance. And there's nothing wrong with using them this way.
>>>
>>>Nothing wrong? I believe that this is, at least, debatable.

>>
>>OK, I'm always up for a good debate ... what are your objections?
>>
>>~~Bonnie
>
>I believe that multiple inheritance (MI):
>- in most cases, shows a flaw in design.
>- and almost always generates maintenance problems.
>I put MI in the same category with things like the Scope Resolution Operator, or event binding. We all hated spaghetti code (sometimes, even if it was our code) for the mess it created, but we were all so happy to get the :: and event binding.
>A complex class hierarchy that uses single inheritance could be challenging, but with MI you can really make it like spaghetti.
>
>I know that in real life we have to compromise, sometimes, and for valid reasons, use interfaces to simulate MI. Some say MI is good, and some say MI is bad - I don't know if there is a clear winner, but I am on the side that believe there is enough wrong with MI. Maybe you meant there is nothing wrong technically, i.e. you can do it, which is true.
>
>I wasn't actually looking for having the debate here, there are people way better than me to do it. I just felt "nothing wrong" was too strong.

(On an infant's shirt): Already smarter than Bush
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform