Book a Demo

Author Topic: Factories with long Hierarchies  (Read 2175 times)

mbaffa

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Factories with long Hierarchies
« on: November 28, 2008, 03:19:25 am »
Hi,

My model has a 3 level inheritance of classes. Something like:
    - Root: Object
    - First Level: Activity, Person, Operation
    - Second Level of Persons: Contact, Client, ....
    - Second Level of Activities: Telephone call, Email, ...

Looking to avoid the use of direct class inheritance I am using the EA template for Factory Method.

As stated in the Factory Method, I have an Interface IObjectFactory, a Concrete Class ObjectFactory that realizes IObjectFactory, an Abstract Class for the Object class and a generalization for Person, Activity and Operation.

The problem is that I have, in fact, a Factory for Object and another one for Person, and onother one for Activities, etc.

In the factory method pattern the Person, Activity and Operation classes inherits from an abstract class Object, the root. So I have a createObject() method for the Object factory.

Since Person has other classes that inherits from it I have to create another factory, the Person Factory. The same architecture must be used for Activity, Operation, etc.

There are some problems with all this:

  1) The problem is that in some cases I need an instance of Person,   Activity or Operation. Since it is abstract it cannot be instatiated

  2) I have a hierarchy of abstract classes

  3) The model became too complex.

Is there any other way to model my problem in a simplified way maintaining it uncoupled.

Thanks in advance.