I am making a football game for Android.
I have a class Player. Player is extended by DefencivePlayer and OffensivePlayer. Each of these classes have a touch event implemented and they are all unique. I have another class, mover, which handles touches which has access to Player. (as seen below)

Player is always either a DefencivePlayer or an OffensivePlayer. I would like the functionality of being able to handle touches by simply calling Player.touch and, depending on which it were, the respective touch method would be called in DefencivePlayer or OffensivePlayer.
I believe my design of having the two classes extend the Player class is wrong because it does not ensure that there are sub classes.
Please help, I am really trying to get a good design here and don’t want to hack anything.
I did a quick test – using your class diagram, I set up the three player classes and created a generic
ArrayList<Player>list of Offensive and Defensive players. Printing out the results of this code:gave me this output:
In other words, the different types of players were interpreted as subclasses, not just as an instance of
Player.From a design perspective, it might be worthwhile making
Playeran abstract class, thus ensuring that no plainPlayerobjects are created, thus thetouch()method will only be executed from an instance of a subclass ofPlayer.