0% found this document useful (0 votes)
80 views4 pages

Factory Overriding

Uploaded by

Rakshith LA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views4 pages

Factory Overriding

Uploaded by

Rakshith LA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

@shraddha_pawankar Date:26/03/2024

Factory Overriding

Based on the requirement, the behavior of the testbench can be changed by


substituting one class with another when it is constructed.
This facility of the uvm factory allows users to override the class without
editing or recompiling the code.

How factory overriding happens?


Look-up Table: The "uvm factory" maintains a lookup table mapping type
identifiers to factory component wrapper classes. This table is like a dictionary
that the factory references to understand which class corresponds to a given
type identifier.

In simple words:

 For example, let's say you have a list of fruits like apples, bananas, and
oranges. Each fruit has its own characteristics, like color and taste.
 Now, imagine you have a friend who wants to know more about these
fruits. You can use your organizer to quickly find out all the details about
each fruit. When your friend asks about apples, you look up "apples" in
your organizer, and it tells you everything you need to know about
them.
 In the "uvm factory," this organizer is like the lookup table. It keeps track
of different types of objects (like fruits) and their characteristics (like
color and taste). So, when you ask the factory for a specific type of
object, it checks its lookup table to find the right one and give you all the
details you need.

Type_ID and Create Method: To create an object of a specific class, you


typically use a combination of type identification (type_id) and a create
method. The type_id identifies the type of object you want to create, and the
create method constructs an object of that type.

1|Page
@shraddha_pawankar Date:26/03/2024

In simple words:
 Type Identification (type_id): This is like telling the waiter what dish you
want. You're specifying the type of food you're craving, like pizza or
pasta. Similarly, in programming, when you use a type_id, you're
specifying the type of object you want to create, like a car or a bike.
 Create Method: Once the waiter knows what dish you want, they pass
that information to the kitchen. The kitchen then makes your chosen
dish. In programming, the create method works similarly. Once you've
specified the type of object you want using the type_id, the create
method constructs (creates) that specific object for you.

 So, just like ordering food at a restaurant, using type_id and the create
method in programming allows you to specify what type of object you
want and then have it created for you. It's like telling the waiter you want
pizza, and then the kitchen making a fresh pizza just for you!

Polymorphism: In object-oriented programming, polymorphism refers to the


ability of objects of different classes to be treated as objects of a common base
class.
In the context of the "uvm factory," when you request an object of a base class
type, the factory is capable of returning an object of a derived class type.
This means that you can request an object of a generic type, and the factory
can provide you with a specialized object that inherits from that generic type.

In simple words:
 Now, let's say you have a garage that can store any type of car. But
instead of labeling each spot in the garage with a specific type of car, you
just have one label that says "Car Parking."

 Here's where polymorphism comes in: even though the garage is labeled
"Car Parking," you can still park a sedan, an SUV, or a truck there. That's
2|Page
@shraddha_pawankar Date:26/03/2024

because all these types of cars share common features, like having
wheels, an engine, and seats. So, the garage can handle any type of car
you bring, treating them all as just "cars."

 In the same way, the "uvm factory" works like this garage. When you ask
it for a "car" (a base class type), it can give you back a sedan, an SUV, or a
truck (objects of derived class types) because they all share common
characteristics. This flexibility allows you to work with different types of
objects without worrying about their specific types, just like parking any
type of car in the "Car Parking" spot.

Derived Type Handle: When you call the create method for a base class type,
the "uvm factory" returns a handle (pointer) to an object of a derived class
type. This allows you to interact with the object using methods and properties
specific to the derived class, even though you initially requested an object of
the base class type.
In simple words:
 Imagine you go to a toy store and ask for a toy car. The store gives you a
special key that can open a box containing not just any toy car, but a
fancy remote-controlled race car!

 In this scenario:

 Base Class Type (Toy Car): This is like asking for a basic toy car. You didn't
specify any special features, just a standard toy car.
 Derived Class Type (Remote-Controlled Race Car): However, what you
get is not just any toy car; it's a super cool remote-controlled race car
with all kinds of extra features and capabilities.
 Handle (Key): The key the store gives you is like a handle or pointer in
programming. It's a special tool that allows you to access and control the
remote-controlled race car inside the box.
So, in simple terms, when you ask for a basic toy car, but the "uvm factory"
gives you back a fancy remote-controlled race car, it provides you with a special

3|Page
@shraddha_pawankar Date:26/03/2024

tool (the handle) to interact with this upgraded car, allowing you to enjoy all its
cool features, even though you initially just wanted a standard toy car.

4|Page

You might also like