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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:28:15+00:00 2026-05-26T19:28:15+00:00

In a system for managing vocational training, I have a CourseBase abstract class, which

  • 0

In a system for managing vocational training, I have a CourseBase abstract class, which I decided on using in favour of an ICourse interface because I’d prefer to avoid duplicating implementation code for all classes derived from the hypothetical, base Course entity. Each course has a list if subjects, with any subject defined by a SubjectBase abstract class. So, I have e.g.

public abstract class CourseBase : BaseObject
{
    public IEnumerable<SubjectBase> Subjects
    {
        get { return new List<SubjectBase>(); }
    }   
}

public abstract class SubjectBase
{
    public string Name { get; set; }
    public string Description { get; set; }
    public int ValidityPeriod { get; set; }
}

Now I want to add a concrete class, LocalCourse, which contains a collection of LocalCourseSubject objects, but because I’m not using an interface for CourseBase, I lose out on covariance, and I need to hide the abstract base’s Subjects property with my new:

public class LocalCourse: CourseBase
{
    public IEnumerable<LocalCourseSubject> Subjects
    {
        get { throw new NotImplementedException(); }
    }
}

I’m sure I’m missing something very obvious here from an OO point of view, but the only solutions I can see are:

  1. Completely omit Subjects from the abstract base, and only add a specifically typed collection property to derived classes.
  2. Implement an interface such as ISubjectCollectionOwner in the abstract base as well as concrete classes.

Please excuse my dimness here, it’s been a while since I’ve had the pleasure of encountering a design issue like this.

  • 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-26T19:28:16+00:00Added an answer on May 26, 2026 at 7:28 pm

    Can’t you just do this:

    public abstract class CourseBase<T> where T : SubjectBase
    {
        public virtual IEnumerable<T> Subjects
        {
            get { return new List<T>(); }
        }
    }
    
    public abstract class SubjectBase
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public int ValidityPeriod { get; set; }
    }
    
    public class LocalCourse : CourseBase<LocalCourseSubject>
    {
        public override IEnumerable<LocalCourseSubject> Subjects
        {
            get { throw new NotImplementedException(); }
        }
    }
    

    I think that would accomplish your short term goal, at any rate, assuming that the general pattern is that each CourseBase inheritor will have a collection of the same type of SubjectBase inheritor. But, if that is the case, this seems like a parallel inheritance hierarchy, which can sometimes be a code smell (not saying that it necessarily is — I don’t know all the details of the domain you’re modeling).

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

Sidebar

Related Questions

I Have a system which is managing the document authorization on different hierarchy level,
I have a situation with a legacy system which uses Java EE Bean Managed
I have a system which I've been wrestling with for a while. Essentially, it
In many big stores/rental/service companys the system they are using for managing customers and
I have a java client which is managing its server calls in new threads
I have been tasked with building a simple web based system for managing a
I have a directory structure where I am managing the requirements of a system
I'm building a system which will have a few channels feeding different clients (MonoDroid,
I have a game. It has a Level class for drawing the level, managing
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to

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.