mardi 24 mars 2015

Best OOP approach to creating Classes in Java

I've come to notice some patterns in the classes I'm creating, for example: I have a class called EnvironmentObject, which has siblings that specialize into different categories like Weapon, Armor. Then these also have siblings who further specialize like Weapon --> Axe. Axes have different types, like Iron, Copper etc. The point is I've been creating a class for ea of the latter, IronAxe.class, CopperAxe.class, etc. I think that the Axe class could hold all the information of the different types inside arrays, like:



String[] weaponTypeNames = { "Copper","Bronze","Iron","Steel"};
Int[] weaponTypeDamage = {"1","3","5","10"};


and then if the object is created just add some parameters in the constructor that will tell the program which type and what stats to have.


which is the best way to layout this? I think that the Polymorphism theorem should apply here.


Aucun commentaire:

Enregistrer un commentaire