Question about superclasses. Pros and cons of an idea.
So I started working on a little RPG to help me learn more about java. Nothing to complex.
However I came across this program. I have a super class named TableList with two subclasses called Weapon and Item which also have subclasses.
Currently I have all the methods inside Weapon and Item, so whenever I try to call a certain method such as getName() on a TableList object the compiler tells me it can't find it.
What are the pros and cons of moving all of the methods to the TableList superclass and the pros and cons of casting my object to (Weapon) or (Item).
For moving the methods I see:
Pros: Not having to cast every time I need an object method called.
Cons: Every Weapon and Item will have the same methods, even though they shouldn't.
For casting I see:
Pros: Each object will still be specialized not sharing methods that they shouldn't have.
Cons: A lot of if statements to figure out what to cast the object too.
Any thoughts on this would be greatly appreciated.