An Abstract Factory is a parent class for many different types of Factories. So for instance you have an Abstract PaintFactory. There are many different types of colors, that will be what each implementation factory will create. But paint also different types of makers, like Sherman-Williams, Behr to name two. So we can then create a ShermanWilliamsPaintFactory and a BehrPaintFactory that will implement the Abstract Factory. You can put the commonality of all paint factories into the Abstract Factory, and just put in the unique differences within the implementation Factories.
So, a Builder is a class that takes many different Objects, combines them to make one type of Object, that needs all of that and build it for the caller. In some senses it is a Factory, but it only creates one type, most of the time.
With an Abstract Factory, every method call creates and returns an object. You can reuse it to create as many objects as you like.
With a Builder, you specify the properties of *one* object with the method calls. Only the last method call will give you the built object. Typically you will have to create a new Builder for building the next object.
Does that help?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I think you are thinking Abstract Method here, since the Factory in Abstract Factory is abstract, so you can't create an instance and call a method. i get those two confused all the time, and it is only because we looked at them both just yesterday that I remember this stuff.
Joined: Jul 11, 2001
Originally posted by Mark Spritzler:
I think you are thinking Abstract Method here, since the Factory in Abstract Factory is abstract, so you can't create an instance and call a method.
Of course I meant that you'd have a concrete instance of a factory from the Abstract Factory pattern... :roll: