Aris wrote: |
Κατ' αρχήν, γιατί θέλεις interfaces; ![Surprise [:O]](/cs/emoticons/emotion-3.gif)
Εξηγούμαι: - Θέλεις να χρησιμοποιείς διάφορα (αλλά παρόμοια) classes για να κάνεις συγκεκριμένη δουλειά (έτσι μου φάνηκε...);. Σε αυτή την περίπτωση, ένα abstract class συνηθίζεται, εάν υπάρχει αρκετός ίδιος κώδικας στα τελικά classes. Επίσης, συνηθίζεται η υλοποίηση ενός Factory που επιστρέφει (με cast στο abstract class ή στο interface) το προς χρήση object. |
|
Αυτό ακριβώς ...
Σε σχέση με το κώδικα μου μπορείτε να μου δώσετε ένα παράδειγμα με abstract class;
Επίσης παραθέτω μία σχετική με το θέμα παράγραφο από το άρθρο :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnguinet/html/drguinet2_update.asp
Interfaces vs. Abstract Base Classes
One of the interesting arguments is whether you should use an interface or an abstract class to describe a set of methods and properties inherited classes must implement.
Dr. GUI solves this using the "IS A" rule: If the essential type of the derived classes "IS A" specialization of the base type, then inherit from an abstract class. Use an interface if the interface is not related to the essential type of the actual objects, because interfaces express what an object "CAN DO," not what it essentially is.
So, because a circle "IS A" generic drawable object, we derive the circle class from the generic drawable object abstract base class to express that relationship. But the circle also "CAN DO" cloning, so we implement the IClonable interface.
There are other ways of looking at this as well—for instance, you might note that you can inherit partial implementation of an abstract class but that you can't inherit implementation of an interface, so you might prefer an interface if there's no common implementation to inherit, especially if the interface can be implemented by a wide variety of classes from many inheritance hierarchies (for example, ICloneable). On the other hand, you might prefer an abstract class for closely related classes that share their implementations and that you want to version at the same time.
For more on this, check out the recommendations in the Visual Basic and Microsoft Visual C#™ product documentation. You might also want to read the entire section on programming with components.
An important note: Be careful when you design your interfaces—once you've published them, you shouldn't change them, even to add a method. (If you add a method, every class that implements your interface will also have to implement that method—and they'll be broken until they do.) You can add methods to classes without breaking derived classes, however.
Πάνος Αβραμίδης