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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:04:44+00:00 2026-06-01T12:04:44+00:00

Lets say i have two classes A and B, which have theirs internal state

  • 0

Lets say i have two classes A and B, which have theirs internal state represented by enum State. Class B extends A to add new functionality, but it also adds new internal state. To be precise, it adds fine-grained state support, by dividing one of the A`s state into two new states.

I also need to use PropertyChangeSupport to monitor state changes.

Currently I have all states defined in class A in enum State. I have protected methods setState() and getState(). To check on state from the outside, I wrote methods isAvaible(), isComplete(), etc. These methods are present only in appropriate class, depending on their hierarchy and state support.

I realy dont like the idea, having all states defined in parent class. How do I implement this correctly in Java? As far as I know, it`s not possible to use inheritance with enums.

  • 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-01T12:04:45+00:00Added an answer on June 1, 2026 at 12:04 pm

    Delegation is preferred to inheritance.

    enum StateA
    {
           AVAILABLE , COMPLETE ;
    }
    
    class A
    {
          private StateA state ;
    }
    
    enum StateB
    {
         AVAILABLE_TO_PUBLIC ( StateA . AVAILABLE ) , AVAILABLE_INTERNALLY ( StateA . AVAILABLE ) , COMPLETE ( COMPLETE ) ;
    
         StateB ( StateA sa )
         {
              this . sa = sa ;
         }
    
         private StateA sa ;
    }
    
    class B
    {
          private StateB state ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Interface lets say ISendOut which I've inherited two different classes from
Lets say I have two classes: public class A { public virtual int Id
Let's say we have these two classes: public class Base { public static int
Let's say I have two models, Classes and People. A Class might have one
So, lets say I have two nearly identical classes in C# and Ruby: C#
Lets say you have two classes, Boss and Employee. There is a bidirectional many-to-many
Let's say I have two classes that look like this: public class ByteFilter {
Let's say I have the following two classes: public class Person { public string
Let's say we have two classes, Foo and Foo Sub, each in a different
Let's say I have two classes, A and B, where B is a child

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.