Search This Blog

Tuesday, May 24, 2011

Tech-No!: Verification Methodologies and Design Patterns: Singleton Pattern


Definition/Intent: Ensure a class only has one instance, and provide a global point of access to it. It is a creational pattern.


Participants & Implementation:

Singleton:

is responsible for creating and storing its own unique instance

defines an Instance operation that lets clients access its unique instance


The “class level” Instance operation will either return or create and return the sole instance; a “class level” attribute will contain either a default indicating there is no instance yet or the sole instance


Applicability:

There must be exactly one instance of a class, and it must be accessible to clients from a well-known access point.

When the sole instance should be extensible by subclassing, and clients should be able to use an extended instance without modifying their code.

Benefits:

Controlled access to sole instance

Permits a variable number of instances

Usage in OVM:

· OVM_TOP – instance of ovm_root. Only one instance of ovm_top

· OVM Factory - only one instance of ovm_factory

References:

i. http://sourcemaking.com/

ii. http://www.oodesign.com

iii. http://home.gwu.edu/~blankeng/Classes/CSCI253/Class%20page%20(spring%202007).htm

vi. http://www.dofactory.com/Default.aspx


No comments: