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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:10:03+00:00 2026-05-16T04:10:03+00:00

I never did proper class design, so bear with me. Let’s say we have

  • 0

I never did proper class design, so bear with me.

Let’s say we have a Project class. Then let’s say we have a ProjectGroup class that has the same members as the Project class, plus a list of Projects.

Should ProjectGroup be the superclass of Project or is ProjectGroup a specialization of Project and the former should be a subclass of the latter?

  • 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-16T04:10:04+00:00Added an answer on May 16, 2026 at 4:10 am

    I won’t bother you with theory, because you’re probably in a hurry to get a quick answer. So here it goes:

    If your two classes are actually implying they should be related by inheritance then ProjectGroup should inherit from Project class. This is how it would look like in C#:

    public class ProjectGroup: Project ...
    

    If they are not, but they use some common class members (that define their state and some functionality over that state), then I’d write an interface and implement it in both classes. C# code again:

    public interface ICommonState ...
    
    public class Project: ICommonState ...
    
    public class ProjectGroup: ICommonState
    {
        IEnumerable<ICommonState> projects
        ...
    }
    

    Edit

    If your classes are actually Project and ProjectGroup and they both have properties like ID and Name in common (for instance), they still shouldn’t be inherited. They just happen to have properties with the same name, but they are basically different entities.

    They could both either

    • implement an ICommonEntity interface – use it when they have the same state+functionality but functionality behaves differently in each of them
    • inherit from CommonEntity class – use it when functionality is completely identical; this way you’ll follow the DRY (don’t repeat yourself) philosophy

    So your component may be an interface or a class (when using composite pattern).

    Direct inheritance between two classes is more suitable where entities imply on being in relation to each other. Like User and Person classes. They can be inherited either way. Depending on the business scenario.

    class User: Person  
    

    This would be the case where you have an application with contacts. Some of them are also users of this very same application.

    class Person: User  
    

    This would be a web site where you can register as a user. In case you fill up some personal details as well your user data becomes of type Person.

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

Sidebar

Related Questions

Which family should I start to learn? (Never did any programming on microcontroller)
I did some tests a while ago and never figured out how to make
Never used a cache like this before. The problem is that I want to
I never actually thought I'd run into speed-issues with python, but I have. I'm
I have never worked with web services and rails, and obviously this is something
I have never hand-coded object creation code for SQL Server and foreign key decleration
I have never written unit tests before, for various reasons. I have a chance
I have a custom container class for which I'd like to write the iterator
I recently did a small jQuery snippet that allows me to show a loading
I did a quiz page for our computer project and I've recently finished it.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.