1

I'm working on an application with many inheritance hierarchies that are not directly related.

Do I have to assign a factory method for each hierarchy in the client code to select a certain class from each hierarchy to instantiate upon the user selection through the GUI?

cspolton
  • 4,495
  • 4
  • 26
  • 34
Hussein
  • 945
  • 1
  • 12
  • 30

2 Answers2

2

Instead if a concret Factory you may take a look at the Abstract Factory

Abstract Factory offers the interface for creating a family of related objects, without explicitly specifying their classes.

Reference

If objects are not related, I think you can't avoid having a factory for each object. Take a look at the Dependency Injection architecture , it could be an interesting option Dependency Injection vs Factory Pattern

Community
  • 1
  • 1
Momo
  • 2,471
  • 5
  • 31
  • 52
0

Have a look at this webpage, which demonstrates using the Abstract Factory pattern with multiple inheritance hierarchies: http://www.dofactory.com/Patterns/PatternAbstract.aspx.

w0051977
  • 15,099
  • 32
  • 152
  • 329