# Need for abstract class

**URL:** <https://verificationacademy.com/forums/t/need-for-abstract-class/28363>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [February 12, 2013, 5:16pm UTC](https://verificationacademy.com/forums/t/need-for-abstract-class/28363 "2013-02-12T17:16:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giri\_lp](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@giri\_lp](https://verificationacademy.com/forums/u/giri_lp)\
**Post date:** [February 12, 2013, 5:16pm UTC](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/1 "2013-02-12T17:16:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [February 12, 2013, 6:52pm UTC](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/2 "2013-02-12T18:52:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![giri\_lp](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@giri\_lp](https://verificationacademy.com/forums/u/giri_lp)\
**Post date:** [February 13, 2013, 5:43pm UTC](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/3 "2013-02-13T17:43:05Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/2):_

Thanks Dave. It helps

---

<div class="post-metadata">

**Author:** ![ShaikhAbuzar](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@ShaikhAbuzar](https://verificationacademy.com/forums/u/ShaikhAbuzar)\
**Post date:** [October 11, 2022, 7:02am UTC](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/4 "2022-10-11T07:02:07Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/3):_

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?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [October 11, 2022, 11:32pm UTC](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/5 "2022-10-11T23:32:47Z")

</div>

_In reply to [Abuzar Gaffari](https://verificationacademy.com/forums/t/need-for-abstract-class/28363/4):_

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.
