Aquarius_Girl
Aquarius_Girl

Reputation: 22936

Why should an abstract class be used for creating a class library?

When and Why to use abstract classes/methods?

When creating a class library which will be widely distributed or reused—especially to clients, use an abstract class in preference to an interface; because, it simplifies versioning. This is the practice used by the Microsoft team which developed the Base Class Library. ( COM was designed around interfaces.) Use an abstract class to define a common base class for a family of types. Use an abstract class to provide default behavior. Subclass only a base class in a hierarchy to which the class logically belongs.

I did not understand the explanation in the above quote. Please explain why should an abstract class be used for creating a class library?

Upvotes: 0

Views: 352

Answers (1)

Alex Aparin
Alex Aparin

Reputation: 4522

You should read articles of such kind very carefully. As I Understood, the main part of article is dedicated to c# language. In terms of such language there is big difference between interfaces and abstract classes. For example, interfaces in terms of c# language is just set of "pure" virtual methods (they cannot have definition within interface, only classes can implement it). Interfaces cannot have constructors. Abstract classes can have constructors. Moreover, c# does not support multiple inheritance ( as opposite to c++ language). In such way, c# interfaces and abstract classes look very different than c++'s one

Upvotes: 2

Related Questions