Skip to main content
added 96 characters in body
Source Link
Philipp
  • 123k
  • 28
  • 264
  • 344

Instead of having a TowerType enum and a lot of if/else/case constructs in your code which handle differences between types, you could make your types of towers separate classes which inherit from an abstract Tower base class.

These classes would set their properties in their constructors. Using sub-classes would also allow you to have a different implementation for the attack-method in each class thus allowing you to implement the different ways of attacking in an elegant way. The same pattern applies to any other situation where you want to run different code depending on the tower type. Like, for example, drawing the tower to the screen.

Instead of having a TowerType enum you could make your types of towers separate classes which inherit from an abstract Tower base class.

These classes would set their properties in their constructors. Using sub-classes would also allow you to have a different implementation for the attack-method in each class thus allowing you to implement the different ways of attacking in an elegant way.

Instead of having a TowerType enum and a lot of if/else/case constructs in your code which handle differences between types, you could make your types of towers separate classes which inherit from an abstract Tower base class.

These classes would set their properties in their constructors. Using sub-classes would also allow you to have a different implementation for the attack-method in each class thus allowing you to implement the different ways of attacking in an elegant way. The same pattern applies to any other situation where you want to run different code depending on the tower type. Like, for example, drawing the tower to the screen.

Source Link
Philipp
  • 123k
  • 28
  • 264
  • 344

Instead of having a TowerType enum you could make your types of towers separate classes which inherit from an abstract Tower base class.

These classes would set their properties in their constructors. Using sub-classes would also allow you to have a different implementation for the attack-method in each class thus allowing you to implement the different ways of attacking in an elegant way.