What is the advantage of using call-backs when inheritance+overide can help achieve the same?Is it recommended to use callbacks?

Hi,
I understand that callbacks provide hook to plugin extra code on top of the original code without modifiying it.Alternatively, we can also extend the class and override the parent with extended class in toplevel.Which among the two methods are preferred? Are there any scenarios where callbacks are preferred over the later method

Do not use callbacks.

Callbacks is a programming mechanism practiced by users prior to the introduction if inheritance. The use of virtual methods and overriding them in extended classes is far more efficient and easier to maintain than callbacks. The only advantage of a callback from some peoples perspective is that you can provide several different callbacks in one class and independently add overrides to each.

In reply to dave_59:

thanks dave!

In reply to shilpa v:

Hi Shilpa
I think deciding on callbacks and factory over ride depends on the DUT you are testing.

Factory Usage: You have a virtual sequence through which we can control the input pattern thoroughly. Usage of factory override is apt in this case.

Callback Usage: You have a layered DUT, example some Protocol DUT which is implemented in OSI layered approach. Now you want to inject/tweak error in a mid level sequence like Network layer (which is between Transport layer and Data Link Layer). To control the sequence items of Network Layer you need lot of control knobs at top level sequece. Instead you can use a uvm_callback which will solve your problem of control the Network layer sequence item easily.

I hope this comment will give you greater insight.
Regards
Nikhil