1.

What Is Factory Pattern ?

Answer»

Factory Pattern Concept : 

Methodologies like OVM and VMM make heavy use of the factory concept. The factory method pattern is an object-oriented design pattern. Like other creational patterns, it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. The factory method design pattern handles this problem by DEFINING a separate method for creating the objects, whose subclasses can then override to specify the derived type of product that will be created. More generally, the term factory method is often used to refer to any method whose main purpose is creation of objects.

Or in simple terms factory pattern help in creation of the object when you dont know the exact type of the object. the normal way of creating the object is :

01.// Normal Type based object creation
02. 
03.// Class object
04.class my_class;
05.int i;
06.endclass
07. 
08.program main;
09.// Create object type my_class
10.my_class obj1;
11.obj1 = new
12.endprogram
13. 
14.// USING Factory I should be able to do the following
15. 
16.program main;
17.base_class my_class_object;
18. 
19.base_class = factory.create_object("my_class"); // See here the type of the object to be created is passed as a STRING so we dont know the exact type of the object
20.endprogram

Factory Pattern Concept : 

Methodologies like OVM and VMM make heavy use of the factory concept. The factory method pattern is an object-oriented design pattern. Like other creational patterns, it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. The factory method design pattern handles this problem by defining a separate method for creating the objects, whose subclasses can then override to specify the derived type of product that will be created. More generally, the term factory method is often used to refer to any method whose main purpose is creation of objects.

Or in simple terms factory pattern help in creation of the object when you dont know the exact type of the object. the normal way of creating the object is :

01.// Normal Type based object creation
02. 
03.// Class object
04.class my_class;
05.int i;
06.endclass
07. 
08.program main;
09.// Create object type my_class
10.my_class obj1;
11.obj1 = new
12.endprogram
13. 
14.// Using Factory I should be able to do the following
15. 
16.program main;
17.base_class my_class_object;
18. 
19.base_class = factory.create_object("my_class"); // See here the type of the object to be created is passed as a string so we dont know the exact type of the object
20.endprogram



Discussion

No Comment Found