Design Pattern - Abstract Factory

G

Guest

Hello,

I analyze this design pattern for a long time but I do not understand how
this pattern work and what the purpose is? (I looked a this site
http://www.dofactory.com/Patterns/PatternAbstract.aspx).

Could anybody try to explain me in his own words how this pattern work and
what the purpose is?

thanks in advance

max

PS: Generally I do not understand why they use (also in Adapter) for example
AbstractFactory factory1 = new ConcreteFactory1(); - Means they define a
object from an abstract class and create in this object a object from a
concrete class. What is the sense of that? :(
 
B

Bruce Barker

the standard Factory pattern is to have a method that creates the object
rather tan using the new operator. but what happens if you waat to add a new
object creation type to the factory?

the case for this is when you create a class that inherits from the classes
the factory generates. say you have a class Widget, and a factory method
Widget.CreateWidget(). now you create a new class MyWidget that inherits
from Widget. simple enough, but how do you get the Factory to create a
MyWidget, rather than a Widget.

this is what the abstract factory pattern is for, a way to replace the
factory code so that when a class calls Widget.CreateWidget() it return an
instance of MyWidget.


-- bruce (sqlwork.com)
 
T

tdavisjr

You usually use a configuration file together with the Abstract Factory
Pattern to get the most flexibility. You would use .NET Reflection to
create the MyWidget object at runtime by passing in the classname
string. There are several articles on this you can do the research on
this. I hopes this points you to the right direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top