what is different between abstract factory and factory method?

Started by
2 comments, last by kSquared 17 years, 11 months ago
I think abstract factory contain factory method. abstract factory is more flexible than factory method. how do you think of that?
Advertisement
Roughly,

"In the Abstract Factory pattern, you create an entirely new class to hold the Create() methods for the objects you want to create. In the Factory Method pattern, you put abstract methods in your own class to Create() objects, and then depend upon the derivatives to implement them.

Abstract Factories are a little more flexible, but a little more complex than Factory Methods. You can change Factories at runtime, but you can't change Factory Method implementations at runtime."

That last sentence is language-dependent. It's possible in C#, for instance, to swap out implementations of a method by calling a delegate instead.

hope that helps,
- k2"Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ} | {Blog/Journal} | {[email=kkaitan at gmail dot com]e-mail me[/email]} | {excellent webhosting}
It's also possible in C++, but it's not a basic feature of the language, but it's no problem to built-in a multi-pass delegate.

An abstract factory creates a factors which creates the objects.
For Example an abstract factory for you GUI can do the following:
factory screen = abstract_gui_factory.createFactory( "TitleScreen" );
screen.createButton();
screen.createStaticText();
/*etc.*/
Roughly,

"In the Abstract Factory pattern, you create an entirely new class to hold the Create() methods for the objects you want to create. In the Factory Method pattern, you put abstract methods in your own class to Create() objects, and then depend upon the derivatives to implement them.

Abstract Factories are a little more flexible, but a little more complex than Factory Methods. You can change Factories at runtime, but you can't change Factory Method implementations at runtime."

That last sentence is language-dependent. It's possible in C#, for instance, to swap out implementations of a method by calling a delegate instead.

hope that helps,
- k2"Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ} | {Blog/Journal} | {[email=kkaitan at gmail dot com]e-mail me[/email]} | {excellent webhosting}

This topic is closed to new replies.

Advertisement