Sign in to follow this  
derek7

what is different between abstract factory and factory method?

Recommended Posts

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,

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.*/

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this