Difference between "creating a derived class" and "override a base class with derived class"

I have a doubt regarding override, when to use override and when to use derived class’s object directly.

For Example:

class E_Base extends Base;

endclass

Now, 1.)if I directly create class E_Base OR 2.)if I use override[uvm type_override] Base with E_Base,
what difference does it make? When to use what?

In reply to dharamvir:

EXtending a class defines a new class which is of the same type as the base class.
Override you can use only if you have a second class of the same type as you want to override.
In other words: extending a class is necessary for using the override.

In reply to dharamvir:

It depends on whether the base class was ever intended to be used alone, or does it have to be extended to be useful. uvm_object and uvm_component are declared as virtual classes and can never be constructed directly. But unfortunately, you can’t declare a base class as virtual and still register it with the factory (this might be fixed in an upcoming version of the UVM).

So if you are going to have multiple extensions from the base class and want to be able to switch between different extensions, you need to create the base class and then override it.

In reply to dave_59:

I got the answer for my second question.(When to use what)
But does it make any difference?

And one more thing, I have a working code where the virtual class is registered with the factory.[You mentioned that this can’t be done.].

In reply to dharamvir:

A virtual class or also called abtsract class does have pure virtual methods. You can make a reference, but you can’t construct them.

In reply to dharamvir:
The difference depends on what you have put in the extended class. If you have only overrides of virtual methods and constraints, there is no difference. But if you add more class members and methods, you cannot access extended class members from a base class variable. That is the case if create() a base class object and override the factory type.

BTW, registering a virtual class with the factory seems to be a tool dependent “feature”. That is because some tools allow you to compile code that have calls to the constructor of a virtual class, but error at runtime if you actually do.

In reply to dave_59:

Thanks, Dave.