the prototype pattern [knight typeknight life speed attack power attack range weaponshort sword [archer typearcher life speed attack power attack range weaponshort bow at the momentthere are only the two units to think aboutbut since you already had moment to contemplate all the other units you are going to add to your unit generatorit should be pretty clear that having separate function for each type of unit you plan on generating in specific building is not great idea to hammer this point home bitimagine what would happen if you wanted to upgrade the units that barracks could generate as an exampleconsider upgrading the archer class so that the weapon it gets created with is no longer short bow but rather long bowand its attack range is upped by five points along with two-point increase in attack power suddenlyyou double the number of functions needed in the barracks classand you need to keep some sort of record of the state of the barracks and the units that it can generate to make sure you generate the right level of unit alarm bells should be going off by now there must be better way to implement unit generationone that is aware of not only the type of unit you want it to generatebut also of the level of the unit in question one way to implement this would be to replace the individual generate_knight and generate_archer methods with one method called generate_unit this method would take as its parameters the type of unit to be generated along with the level of unit you wanted it to generate the single method would use this information to split out into the units to be created we should also extend the individual unit classes to alter the parameters used for the different unit attributesbased on level parameter passed to the constructor when the unit is instantiated