keshav_joshi
02-28-2009, 04:37 AM
Hi ,
I was innterested in knowing what eactly are policy objects?
Also,how copy & do_copy,compare & do_compare are differenet?
In the compare function argument,is it ok if I dont pass the ovm_comparer argument?
Regards
keshav
gordon
02-28-2009, 12:13 PM
Hi ,
I was interested in knowing what exactly are policy objects?
Hi Keshav,
To the user, the policy object is a neat way of choosing or customizing an algorithm for doing an aspect of the functionality of a component or data item in our test environment, like printing, or comparing, or serializing, or cloning.
The Policy Pattern (also commonly known as the Strategy Pattern) is a Design Pattern in Object-Oriented Programming where an algorithm for doing a particular task can be encapsulated in a class, descended from a common base class, along with possible alternate algorithms in other subclasses.
In OVM2, some of the methods allow an optional parameter of a policy class to be passed.
E.g. the print() method in an item prints a table by default, but if you instead run print(ovm_default_line_printer) you get your item printed out on one line.
The argument is a whole class which contains part of the print() algorithm.
You can create your own, e.g. by subclassing ovm_tree_printer, to print a hierarchy in a particular way, and then instantiate one and use print(my_tree_printer), and so on.
See OVM2 Class Reference / Chapter "Policies" for more info on OVM policy objects.
See http://en.wikipedia.org/wiki/Strategy_pattern to find out more about Design Patterns and this one in particular.
Also, how copy & do_copy, compare & do_compare are different?
copy()/compare() are methods the user should call, and the do_xxxx() equivalents are method hooks to allow the user to extend the copying or comparing functionality in their subclass, if their needs are different from the default. [of course, for the default copy()/compare() to work, the fields to be considered must be introduced via the `ovm_field_xxx macros]
In the compare function argument, is it ok if I dont pass the ovm_comparer argument?
Yes. You will see in OVM2 Class Reference / Base / ovm_object / Methods that the signature for the compare() method has ovm_comparer comparer=null which means that the default will be null, and OVM will use its default comparer.
Powered by vBulletin™ Version 4.0.3 Copyright © 2010 vBulletin Solutions, Inc. All rights reserved.