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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:32:16+00:00 2026-06-15T18:32:16+00:00

I realise that it’s generally a bad idea to put objects of different types

  • 0

I realise that it’s generally a bad idea to put objects of different types into one collection, and that I can do it by making the type be “object”, but I have a situation where I can’t think of an alternative, and was hoping someone else could.

Situation:
At the end of a turn in a game I would like the player to effectively pick up a card from a deck. The card will be one of three types of card. Usually the card will go into the player’s hand and allow the player to perform a standard action, but I want there to be a chance of the player getting a special card, with its action being specific to that card, and there to be a chance of the player getting a card which takes its action immediately rather than going into the player’s hand. These types cards have nothing in common, so it doesn’t seem to make sense to have a common interface, but I want them to be randomly mixed through the deck, so I’d like to have them all in one collection.

Does anyone have any design suggestions? (I’m rather new to OO design)

  • 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-15T18:32:17+00:00Added an answer on June 15, 2026 at 6:32 pm

    Your idea of using an interface was on the right track. However, you don’t need to make the “special action card” implement a Card interface: make a different interface for it (say, Deckable), make the Card interface inherit it, and then implement that interface in your “special action card” class.

    interface Deckable {
        void takeAction();
    }
    interface Card extends Deckable {
        int getRank();
        int getSuit();
    }
    class PlayingCard implements Card {
        ...
    }
    class SpecialActionCard implements Deckable {
        ...
    }
    

    Now you can create a list of Deckable, and mix your special cards into it:

    List<Deckable> deck = new ArrayList<Deckable>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realise that you can open the google maps app ready for directions by
I realise there might be similar questions but I couldn't find one that was
I realise that you can't use in app purchases for real things. But does
I realise that the view/controller stuff will be different between Mac and IPhone apps
I realise that this is a very basic question, but it is one which
I realise that I can't access Form controls from the DoWork event handler of
I realise that in vim, I can highlight trailing spaces at the end of
I realise that I can do this via a loop, but was wondering if
Firstly, I realise that this is a very similar question to this one: Which
I realise that I can prevent unauthenticated users from accessing views at controller level

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.