Need for abstract class

Why do we need abstract class? I am thinking that by using polymorphism we can share the class. Please clarify me.

Prior to SV 1800-2012, abstract classes served two purposes:

  1. A partially implemented class - Abstract classes act as expressions of general concepts from which more specific classes can be extended. An abstract class defines some default functionality with virtual methods, and requires you to add additional functionality with pure virtual methods (method prototypes with no implementation). Although the language does not require having a pure virtual method in your abstract class, there is usually no point in using the abstract class without extending it and providing some virtual method overrides. You cannot create an object of an abstract class type; however, you can reference extended objects from an abstract class typed variable. You are using polymorphism to access the virtual method in the extended class, and those virtual methods will access members of the extended class.
  2. An interface class containing only pure virtual methods - a completely unimplemented class. This is a way for one class to communicate with another class through a published API that is made up of the pure virtual method prototypes. That one class just needs to contain an abstract class variable to reference the other implemented object. Since SystemVerilog only allows for single inheritance, this also serves to keep the inheritance hierarchies of the two classes separate.

The difference between these two contrivances is a matter of degree in implementation inside the base class. However, SystemVerilog 2012 has formalized the concept of interface classes in a way that allows for multiple inheritance of interface classes. These are all concepts borrowed from Java, so you can search for more information in that domain.

In reply to dave_59:

Thanks Dave. It helps

In reply to dave_59:

Great explanation!
But please can you give one realtime application/example where we use abstract class. So that we will be more clear why we need abstract class?

I know that UVM base classes are abstract class. Why UVM developers have not used normal classes as base classes?

In reply to Abuzar Gaffari:

Declaring a base class as an abstract class is an indication to the user (and the compiler) that it makes no sense to construct this class object directly—you must always declare an extension of the abstract class and construct that.

It is not much different than having local and protected class members, or even read/write file permissions. They are not necessary to implement functionality, they just provide an easy mechanism for catching mistakes early on.