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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:46:38+00:00 2026-05-14T03:46:38+00:00

I will use (again) the following class hierarchy: Event and all the following classes

  • 0

I will use (again) the following class hierarchy:

Event

and all the following classes inherit from Event:

SportEventType1 SportEventType2 SportEventType3 SportEventType4

I have originally designed the Event class like this:

public abstract class Event
{
    public abstract EventType EventType { get; }
    public DateTime Time { get; protected set; }

    protected Event(DateTime time) {
        Time = time;
    }
}

with EventType being defined as:

public enum EventType {
    Sport1,
    Sport2,
    Sport3,
    Sport4
}

The original idea would be that each SportEventTypeX class would set its correct EventType. Now that I think of it, I think this approach is totally incorrect for the following reasons:

  1. If I want to later add a new
    SportEventType class I will have to
    modify the enum
  2. If I later decide to remove one
    SportEventType that I feel I won’t
    use I’m also in big trouble with the
    enum.
  3. I have a class variable in the Event
    class that makes, afterall,
    assumptions about the kind of
    classes that will inherit from it,
    which kinda defeats the purpose of
    inheritance.

How would you solve this kind of situation? Define in the Event class an abstract “Description” property, having each child class implement it? Having an Attribute(Annotation in Java!) set its Description variable instead? What would be the pros/cons of having a class variable instead of attribute/annotation in this case? Is there any other more elegant solution out there?

Thanks

  • 1 1 Answer
  • 1 View
  • 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-14T03:46:38+00:00Added an answer on May 14, 2026 at 3:46 am

    I would not do an enum for an EventType, if your subclass is going to be EventTypes. Enums are good for a fixed set of options – in your case, you want the flexibility of inheritance, so just use subclassing directly.

    If it’s just a matter of description, I would do something like:

    public abstract class Event
    {
        public string Description { get; private set;}
        public DateTime Time { get; protected set; }
    
        protected Event(string description, DateTime time) {
            this.Description = description;
            Time = time;
        }
    }
    

    This just lets your subclasses specify this for you, and it sounds like that is what you’re after anyways.

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

Sidebar

Related Questions

I will use jQuery to perform the following: Upon click of elements with the
I will use the following javascript to display a Google Map Window in a
I will use quickaction for a listview. I use this example for quickaction: http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
Many times I will use the same font scheme for static text in a
When we will use DrawItem for a listbox? Normally, if the listbox is ownerdraw,
My script below will use two external tables to fill two separate tables, but
I am writing my first project that will use autoconf and teaching it to
I want to start an application which will use ajax push, however the web
When Excel determines the axis values it will use to represent your data in
I have to use SQLPLUS for my database class, and our first assignment is

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.