0

Can anybody tells me the significance of abstract class when we can achieve the the inheritance feature by normal class?

Thanks, Prashant N

3 Answers3

0

An abstract class can't be instantiated, so it's used when you want to force the existence of a concrete implementation. Ej, a base class for all objects in DDBB could be declared as:

abstract class Identifiable{
    public int Id {get; set;}
}

Then, every class in your model is forced to have an Id field, while at the same time none can make use of new Identifiable() as it doesn't make any sense.

Oscar
  • 13,594
  • 8
  • 47
  • 75
0

In general an abstract class is used to define an implementation and is intended to be inherited from by concrete classes. It's a way of forcing a contract between the class designer and the users of that class. If we wish to create a concrete class (a class that can be instantiated) from an abstract class we must declare and define a matching member function for each abstract member function of the base class. Otherwise, if any member function of the base class is left undefined, we will create a new abstract class.

An abstract class is, conceptually, a class that cannot be instantiated and is usually implemented as a class that has one or more pure virtual (abstract) functions.

Example:

`class AbstractClass {
 public:
  virtual void AbstractMemberFunction() = 0; // Pure virtual function makes
                                             // this class Abstract class.
  virtual void NonAbstractMemberFunction1(); // Virtual function.

  void NonAbstractMemberFunction2();
}; 
Erica
  • 213
  • 2
  • 16
0

The significance of the abstract class is that we can to describe an abstract interface for something from real world (without any realization of it). Because of this the abstract classes are using widely in the COM technology in the Windows.

For example, if you need to do a flexible mechanism for creation of a device drivers in some system then you, probably, need to describe an entities like Device, Driver etc. If they was described well-engineered then users of your mechanism will create a new drivers easy.

Serge Roussak
  • 1,731
  • 1
  • 14
  • 28