0

I am designing factory patterns for a game and I have this two options:

  1. create an abstract Factory class and derived factory classes

  2. create only 1 Factory class, which will be the instantiation of all Entity types

What are the advantages/disadvantages of each? For option 1, it is a lot easier for me as a programmer since I have so many types of entities, although option 2 has better polymorphism. Why would one choose option 2 instead?

cscisgqr
  • 29
  • 1
  • 5
  • A small code example of each pattern would be easier to compare. In the meantime, you may be interested in the [Differences between Abstract Factory Pattern and Factory Method](https://stackoverflow.com/a/50786084/1371329). – jaco0646 Mar 07 '19 at 22:58

1 Answers1

0

The advantage of (2) is that if your program evolves to use another family of entities, you will already have the pattern structure in place -- your client code will create the entities through the abstract factory interface.

(1) involves fewer classes, and is fine if you are certain that you will not need another family of entities (but if this really were the case, I think you wouldn't be using a factory pattern here at all).

ComDubh
  • 793
  • 4
  • 18