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 8360231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:23:41+00:00 2026-06-09T11:23:41+00:00

I need advice on interfaces. I have a class called Unit which can attack

  • 0

I need advice on interfaces. I have a class called Unit which can attack other units. The attack can be air or ground. I need single method to achieve attacking called attack(). Some units can only attack ground units, some air units or both.

This is what I’ve come up so far:

public interface Attack() {
    public void attack(SCObject object);
}

public interface GroundAttack() extends Attack {
    public void groundAttack(SCObject object);
}

public interface AirAttack() extends Attack {
    public void airAttack(SCObject object);
}

I have can have different units:

Unit extends SCObject implements GroundAttack {
}

Unit extends SCObject implements AirAttack {
}

Unit extends SCObject implements AirAttack, GroundAttack {
}

The problem is this implementation will reveal the two ground and air options whereas I only want attack() method to be visible.
Can you propose solution or does this seem ok to you?

  • 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-06-09T11:23:42+00:00Added an answer on June 9, 2026 at 11:23 am

    I would use

    public interface Attack {
        public boolean canAttack(SCObject object);
        public void attack(SCObject object);
    }
    

    I don’t see a reason to have a specific ground or air attack method given you didn’t want to expose this behaviour.

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

Sidebar

Related Questions

I need advice or directions on how to write an algorithm which will find
I'd need advice on following situation with Oracle/PostgreSQL: I have a db table with
I really need advice on how to do the following. I have tried several
I think I have this working but I need advice. I'd like to know
I have 3 tables, I need advice on how to get data from them.
I need some advice on a little project im doing. I have a database
I am just studying so I need your advice. I have found a code
I have a php script which i would need the following 3 web browsers
I have a method on which I need to pass an enum as a
I need some advice / ideas if someone is inclined to help: I have

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.