Re: Abstract factory pattern



"Tony Johansson" <johansson.andersson@xxxxxxxxx> wrote in message
news:aXw_e.34853$d5.190068@xxxxxxxxxxxxxxxxxx
> Hello!
>
> Assume you have three concrete factories cadillac, Volvo and Fiat.
> We also assume that each one only consist of Engine, Chassis and Steering.
> So in the abstract factory and the concreate factories you will have
> createEngine, createChassis and createSteering.
>
> Normally a single instance of a Concretefactory class is created at
> run-time.
> This concreate factory creates product objects having a particular
> implementation.
>
> Now to my question when the client create a Concrete factory for cadillac
> it will receve a reference to this created object as I mentioned above.
> But this will mean that the client know that this reference is a reference
> to a cadillac object handling products for this car such as Enhine,
> Chassis and Steering.
>
> I can't understand this but the point in Abstract pattern is that the
> client should not be aware of the concreate classes.
>
> But it will be aware of it when the ConcreateFactory is created
>


Hi Tony,

The calling code will use the concrete factory to return objects of the
supertype.

Engine myEngine = myFactory.CreateEngine();

This code doesn't change, regardless of how you created the concrete factory
object 'myFactory' (which can be done in a Factory method, and therefore
isolating the creation of the object from its use. The line of code above
is not coupled to the notion of a Cadillac or a Volvo. It doesn't 'know'
that the engine is a Cadillac engine. The creation method may have looked
in a config file to decide which concrete factory to use, and therefore,
NONE of the code may be aware of the notion that this is a Cadillac engine.

And that's the point.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--


.