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

  • Home
  • SEARCH
  • 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 7184847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:17:09+00:00 2026-05-28T18:17:09+00:00

Is it possible to copy this functionality of offering an abstract method in an

  • 0

Is it possible to copy this functionality of offering an abstract method in an enum that inner enum constants must override and provide functionality to?

public enum Logic {
    PAY_DAY {
        @Override
        public void acceptPlayer(Player player) {
            // Perform logic
        }
    },
    COLLECT_CASH {
        @Override
        public void acceptPlayer(Player player) {
            // Perform logic
        }
    }
    ,
    ETC_ETC {
        @Override
        public void acceptPlayer(Player player) {
            // Perform logic
        }
    };

    public abstract void acceptPlayer(Player player);
}

If it can’t::
Could you provide a way which I can implement lots of specific logic in a similar manner?

Edit :: I know that enums in C# are not really ‘objects’ like they are in Java, but I wish to perform similar logic.

Edit :: To clarify, I do not want to provide concrete classes for each specific bit of logic. IE, creating an interface acceptPlayer and creating many new classes is not appropiate

  • 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-28T18:17:10+00:00Added an answer on May 28, 2026 at 6:17 pm

    Here’s one option – not using enums, but something similar-ish…

    public abstract class Logic
    {
        public static readonly Logic PayDay = new PayDayImpl();
        public static readonly Logic CollectCash = new CollectCashImpl();
        public static readonly Logic EtcEtc = new EtcEtcImpl();
    
        // Prevent other classes from subclassing
        private Logic() {}
    
        public abstract void AcceptPlayer(Player player);
    
        private class PayDayImpl : Logic
        {
            public override void AcceptPlayer(Player player)
            {
                // Perform logic
            }
        }
    
        private class CollectCashImpl : Logic
        {
            public override void AcceptPlayer(Player player)
            {
                // Perform logic
            }
        }
    
        private class EtcEtcImpl : Logic
        {
            public override void AcceptPlayer(Player player)
            {
                // Perform logic
            }
        }
    }
    

    You say that you don’t want to provide a concrete class for each bit of logic – but that’s basically what you’d be doing in Java anyway, it’s just that the class would be slightly hidden from you.

    Here’s an alternative approach using delegates for the varying behaviour:

    public sealed class Logic
    {
        public static readonly Logic PayDay = new Logic(PayDayAccept);
        public static readonly Logic CollectCash = new Logic(CollectCashAccept);
        public static readonly Logic EtcEtc = new Logic(player => {
            // An alternative using lambdas...
        });
    
        private readonly Action<Player> accept;
    
        private Logic(Action<Player> accept)
        {
            this.accept = accept;
        }
    
        public void AcceptPlayer(Player player)
        {
            accept(player);
        }
    
        private static void PayDayAccept(Player player)
        {
            // Logic here
        }
    
        private static void CollectCashAccept(Player player)
        {
            // Logic here
        }
    }
    

    In both cases, you still get a fixed set of values – but you won’t be able to switch on them. You could potentially have a separate “real” enum, but that would be a bit messy.

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

Sidebar

Related Questions

is it possible to copy a variable like this this? class Colours { var
Would it be possible to copy this C# program in PHP? var chatsrv =
Still learning my ways around C# generics... is it possible to achieve this functionality?
Currently, I have bunch of triggers that do the same thing. This is copy-pasted
Is it possible to copy a single file to multiple directories using the cp
I would like to know if it is possible to copy/move files to a
Possible Duplicate: Best way to copy the entire contents of a directory in C#
Is it possible to use RoutedCommands such as ApplicationCommand.Copy, ApplicationCommand.Paste, etc in Silverlight 4
Does anyone know if its possible to use phing to copy an entire folder
i want to copy multiple files at once through xcopy. is it possible. i

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.