Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7641015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:48:59+00:00 2026-05-31T08:48:59+00:00

I am making a football game for Android. I have a class Player. Player

  • 0

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)

FootballGameUML

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:49:00+00:00Added an answer on May 31, 2026 at 8:49 am

    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:

    players.add(new OffensivePlayer());
    players.add(new DefensivePlayer());
    players.add(new OffensivePlayer());
    players.add(new OffensivePlayer());
    players.add(new DefensivePlayer());
    
    for(Player p: players)
        p.touch();
    

    gave me this output:

    Touched offensive player.
    Touched defensive player.
    Touched offensive player.
    Touched offensive player.
    Touched defensive player.
    

    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 Player an abstract class, thus ensuring that no plain Player objects are created, thus the touch() method will only be executed from an instance of a subclass of Player.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a zero-player c# wpf football simulation and I have the field laid
Making game of life I need to a have a grid that is 30x20
Making a ship game because I am incredibly original.. With that aside, I have
Making my first steps with NHibernate, I'm trying to have it creating my Tables
Making a mobile friendly site, I have a single field and a submit button.
Making a new shooter game here in the vein of Galaga (my fav shooter
Making a flash page that can cycle through these three images on mouseclick. For
Does making a class field volatile prevent all memory visibility issues with it in
making a multi-language site with codeginiter. I have created two folders. One for french
Making a new class in VS10 gives me using System; using System.Collections.Generic; using System.Linq;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.