jeudi 1 septembre 2016

Factory pattern : What to do when factory class is too big?

I am using entity-base-components system.

I have many type of stationary objects e.g.

  1. Wall = blocks
  2. Fire Turret = blocks + shooter
  3. Water Turret = blocks + shooter
  4. Bunker = blocks + spawner

Here is the factory of stationary objects :-

class StationaryObject{
    enum typeOfObject_enum{WALL,FIRE_TURRET, ....};
    Entity* create(typeOfObject_enum theType){ //it is enum
        switch(theType){
            case WALL: ... create some mesh, some physic body  ....
            case FIRE_TURRET: .... create some mesh, some physic body+ unique logic 20 lines ....
            ....
        }
    }
}

It works really good.

Question:
Now I want to create 100 types of Stationary objects, where should I store it?
Store all of them in class StationaryObjectwill make the class too big (?).

Note that there are tiny-but-unique logic in each type of object.

Aucun commentaire:

Enregistrer un commentaire