Abstract factory and Application layers

  • Thread starter Thread starter Julia
  • Start date Start date
J

Julia

Hi,

I have an application composed from layers like the following

A
--B
---C

A is the top layer
C uses an Abstract Factory to Create Concrete classes
I wonder if A should create the concrete factory,pass it to B,and than B
will pass it to A
or maybe it is better to create a Concrete factory in B

what are the advantages in disadvantages in each approaches?
create the Concrete factory in the upper most layer
or in the a layer which is one level higher that the layer which uses the
factory?

Thanks
 
hello Julia,

I honestly have to think about what you mean by "layers" because this
doesn't seem to be the same as Buschmann's Layers pattern.

I think you are saying this:
The 'A' layer is a set of interfaces and base classes.
The 'B' layer is a set of concrete classes inherited from 'A' and
The 'C' layer is composed of the collaborating objects (the controllers) who
need to use the classes in 'B'. You want to know where to create your
concrete factory derived from your Abstract Factory base class.

In B.

The concrete factory is, by definition, coupled to the classes it creates.
All factory methods have to know the name of the object that they create
(that's their point). (Factories aren't the only way to abstract object
creation, of course, but that is too much for a Newsgroup posting :-).

Therefore to have "layers" that are cohesive in nature, you want your
concrete factory to be packaged in with the classes that it creates. If I
guessed about your layered structure correctly, then you would place the
abstract factory in A (since it defines types in A), the ConcreteFactory
that inherits from the AbstractFactory in B, and the FactoryFactory in B
(since it creates types of type AbstractFactory, and those types are
declared in B).

--
--- 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.
 
hello Julia,

I honestly have to think about what you mean by "layers" because this
doesn't seem to be the same as Buschmann's Layers pattern.

I think you are saying this:
The 'A' layer is a set of interfaces and base classes.
The 'B' layer is a set of concrete classes inherited from 'A' and
The 'C' layer is composed of the collaborating objects (the controllers) who
need to use the classes in 'B'. You want to know where to create your
concrete factory derived from your Abstract Factory base class.

In B.

The concrete factory is, by definition, coupled to the classes it creates.
All factory methods have to know the name of the object that they create
(that's their point). (Factories aren't the only way to abstract object
creation, of course, but that is too much for a Newsgroup posting :-).

Therefore to have "layers" that are cohesive in nature, you want your
concrete factory to be packaged in with the classes that it creates. If I
guessed about your layered structure correctly, then you would place the
abstract factory in A (since it defines types in A), the ConcreteFactory
that inherits from the AbstractFactory in B, and the FactoryFactory in B
(since it creates types of type AbstractFactory, and those types are
declared in B).


--
--- 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.
 
Back
Top