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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:26:51+00:00 2026-05-31T15:26:51+00:00

How to model a domain when you have a base class and 2 classes

  • 0

How to model a domain when you have a base class and 2 classes extending this base class and only one of derived class has a relationship with another object.

Example:

public abstract class Base  
{  
    public abstract void method();  
}

public class1 extends Base  
{
    public void method()
    {
         do some stuff
    }
}

public class2 extends Base  
{
    private Class3 class3;       

    public void method()
    {
         do other stuff
    }

    public Class3 getClass3(){...}

    public void setClass3(Class3 class3){...}
}  

Is this model breaking Liskov principle? I think so because of this relation with class3, so we have to figure out how to model without this relation or to move this relation to Base. If I have a part of program that deal with Class2 to handle the relation whith Class3 I can’t work with base class without cast to class2.

Is this thought right?

Clarifying…

Let’s think in learning model. We have Courses and CourseClasses. We can also have a online courses and presencial courses. In presencial courses we may face with cost of this training. So costs only make sense to presencial environment. CourseClasses could have range dates or quatitative dates.

Today I have this model:

Course
{
    ...
}

public abstract class CourseClass
{
    private Course course; 

    // getter and setter to course

    public abstract Enrollment enroll(Person student);
}

public class QuantitativeCourseClass
{
    public Enrollment enroll(Person student)
    {
        // enroll for quantitative
    }
}

public class RangeCourseClass
{
    public Enrollment enroll(Person student)
    {
        // enroll for range
    }
}

Now I have to deal with costs and till this moment presencial course isn’t important to me but now, cost only make sense to presencial enviroment.

My problem is: I need to deal with CourseClass object in cost module because I need some stuff of courseClass, but the relationship of cost is with RangeCourseClass because QuantitativeCourseClass don’t make sense to prensecial environment.

The question about liskov is about how to convence my team to make some modifications in this model.

  • 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-31T15:26:52+00:00Added an answer on May 31, 2026 at 3:26 pm

    I think you have mixed up the direction of LSP (Liskov Substitution Principle): LSP is (strong) behavioral subtyping, not strong behavioral supertyping. So LSP is not working against your example, but for your example:

    Is this model breaking Liskov principle? I think so because of this
    relation with class3, so we have to figure out how to model without
    this relation or to move this relation to Base. If I have a part of
    program that deal with Class2 to handle the relation with Class3 I
    can’t work with base class without cast to class2.

    Your model is not breaking LSP. If you have a part of program that uses some variable var that deals specifically with Class2 (i.e. parts not present in Base), you need to declare var to be of Class2. So no downcast is necessary. And LSP guarantees that var behaves as Base, too, so no explicit upcast is necessary, either.

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

Sidebar

Related Questions

I have this domain model: class Person < ActiveRecord::Base composed_of :address, mapping: [%w(address_street street),
I have a class in my domain model root that looks like this: namespace
I have a an object stored in the model called domain, which has two
I'm using ruby 1.9.2 and rails 3.2.2. I have a 'domain' model (domain.rb): class
My domain model is this: we have a bunch of schools as the root
I have a form that handles editing of a domain model (A). This domain
Given you have a domain model with a simple parent / child relationship, and
I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
I have domain model developed based on DDD concept, pretty much Object Oriented and
I have a model, Domain , which has a text field, names . >

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.