What can be the harm in constructing analysis_port in new function of monitor?

In most of the examples which we see including the UVM cookbook, the analysis ports inside the monitor based on uvm_monitor are constructed in the build_phase of the monitor.

My question is can someone point out the part where there is a harm in doing the above in the new function of the monitor so implemented.

The analysis_port will most likely be created, there should not be any cfg dependency like active passive agent.

The advantage is that all the “new” code is placed in new function. Clean code that’s it.

Regards,
Prashant

The problem is you used the term “most likely” instead of “always”.

When extending a class new() constructor, it does not override the base constructor, only adds to the base. The build_phase was created to give you the opportunity to override the new constructor. Anything you put in the new() constructor of a class removes that opportunity.

We tell people “don’t put anything in the constructor unless it absolutely has to be there”, like the construction of an embedded covergroup.

Then from the UVM’s point of view, the clean coding way is putting all contained class construction in the build_phase().