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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:38:12+00:00 2026-05-25T09:38:12+00:00

I am currently working on a project where I am attempting to hide as

  • 0

I am currently working on a project where I am attempting to hide as much detail about a hierarchy I have created as possible. I want to do this to minimize the amount of information the user needs to know about objects (and to control what they can do to the state of the object). In addition, I’m using the pattern to limit what kinds of objects the application can make, and limit it to creation from the factory.

The main issue I am having, however, is that there are a few different kinds of interfaces I would like to expose. Each interface is has additional functionality that I don’t believe should be shared, and I would like to keep these interfaces separated. Finally, I don’t know what new interfaces may come in the future, but I’d like to try and be ready for them.

Weapon:

public interface Weapon extends GameObject {
    Number attack();

    boolean addWeaponAttribute(WeaponAttribute attribute);
}

Firearm:

public interface Firearm extends Weapon {
    void reload(Number rounds);
}

My question is what would be the best way to have the factory produce objects with different interfaces? Here’s what I am thinking “the best would be”:

  1. The most clear to the user (it’s obvious what they’re asking for and what they’re getting back)
  2. The best for future expansion (I am uncertain what new interfaces I will be adding to this system).

Here’s what I have been thinking so far:

Create properly named methods for each interface

public static Firearm getFirearm(String firearmName) {
    ...
}

public static Weapon getWeapon(String weaponName) {
    ...
}

Do the above, but produce the factories in separately named classes

public class WeaponFactory {
    public static Weapon getWeapon(String weaponName) {
        ...
    }
}


public class FirearmFactory {    
    public static Firearm getFirearm(String firearmName) {
        ...
    }
}

Something completely different

I’m open to suggestions, and changes. This is a flexible project, so I can change as much as I want to (in terms of this portion of the project) to make a better result.

Also – As a side note, I was uncertain if this question was too open-ended or not for SO. If I made a mistake posting here, let me know and I’ll move my question elsewhere.

  • 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-25T09:38:13+00:00Added an answer on May 25, 2026 at 9:38 am

    maybe just use the factory method design pattern like

    interface GameObject {}
    class WeaponAttribute {}
    interface Weapon extends GameObject {
        Number attack();
        boolean addWeaponAttribute(WeaponAttribute attribute);
    }
    interface Firearm extends Weapon {
        void reload(Number rounds);
    }
    class WeaponBaseClass implements Weapon {
        WeaponBaseClass(WeaponName weaponName) {
            this.weaponName=weaponName;
        }
        @Override public Number attack() {
            return null;
        }
        @Override public boolean addWeaponAttribute(WeaponAttribute attribute) {
            return false;
        }
        public String toString() {
            return weaponName.toString();
        }
        final WeaponName weaponName;
    }
    class FirearmBaseClass extends WeaponBaseClass implements Firearm {
        public FirearmBaseClass(WeaponName weaponName) {
            super(weaponName);
        }
        @Override public void reload(Number rounds) {}
    }
    enum WeaponName {
        knife, sword, colt45, glock19, glock19WithLaser;
    }
    class WeaponCreator {
        Weapon create(WeaponName weaponName) {
            switch (weaponName) {
                case knife:
                case sword:
                    return new WeaponBaseClass(weaponName);
                case colt45:
                case glock19:
                    return new FirearmBaseClass(weaponName);
                default:
                    return new WeaponBaseClass(weaponName);
            }
        }
    }
    class FancyWeaponCreator extends WeaponCreator {
        Weapon create(WeaponName weaponName) {
            Weapon weapon = null;
            switch (weaponName) {
                case glock19WithLaser:
                    weapon = super.create(WeaponName.glock19);
                    // whatever it needs
                    return weapon;
                default:
                    return new WeaponBaseClass(weaponName);
            }
        }
    }
    public class Main {
        public static void main(String[] args) {
            System.out.println(new WeaponCreator().create(WeaponName.knife));
            System.out.println(new WeaponCreator().create(WeaponName.colt45));
            System.out.println(new FancyWeaponCreator().create(WeaponName.glock19WithLaser));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on project about car travelling http://wayfi.ru and I have encountered
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am currently working on a project where I have several string that may
Iam currently working on a project where i have to read serial port continuously.
I'm currently working on a project with Codeigniter. I have one controller called Cat
I'm currently working on a django project. I'm attempting to add a UserProfile model
I have been working on this project for my job, which involves backing up
I am currently working on Project Euler for fun, and use Haskell for practicing.
I am currently working on a project that I would like to create a
I am currently working on a project that I built using the alpha C4

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.