Explain Factory pattern?

Answer Posted / swetha

Factory Design Pattern is a simple decision making class
that returns one of several objects depending on the data
provided. It comes under creational type of design pattern.


Example:

Suppose say that want to write the code to perform
arithmetic calculations. Initially you decided to write code
for only Addition and Subtraction. And later on you decided
to add more functionality by including Multiplication and
Division. Now, if you don't use Factory Design Pattern, we
need to change the entire code to include additional
functionality. But, when we use Factory Design Pattern, It
is easy to add additional functionality when needed without
disturbing previous code.

In factory class we create the instance of the classes
addition, subtraction, division and multiplication based on
the operator selected.

In this way Factory Design Pattern is useful.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between stored procedure vs function?

581


What’s the catch?

628


What is data caching?

562


What is the difference between user control an custom control?

618


What is dynamic web page with example?

529






Can anyone please tell me that the question posted on this website are Sufficient for the interview with 2+ year experience in .net

1509


Let's say I have an existing application written using vb6 and this application utilizes windows 2000 com+ transaction services. How would you approach migrating this application to.net?

505


How do you declare delegates and are delegates and events one and the same and explain how do you declare delegates and invoke them ?

3416


What is the difference between custom web user control and a custom web server control?

507


How many types cache in asp net?

532


What is a server farm in iis?

539


What is server side in asp.net?

501


Define machine.config in .net?

557


What are custom user controls in asp.net?

522


How does asp page work?

551