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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:35:30+00:00 2026-06-11T17:35:30+00:00

Yesterday I asked this question, and the solution posted by @JB Nizet worked perfectly.

  • 0

Yesterday I asked this question, and the solution posted by @JB Nizet worked perfectly. However, that answer, as well as a few other answers/comments got me thinking in a different direction altogether.

Essentially, I have the following classes:

  • Load
  • HttpLoad extends Load
  • Target
  • HttpTarget extends Target
  • Controller

The Controller‘s job is to Target::fire() a Load, and doesn’t care which Target is firing which Load:

// Inside Controller.java
Target target = getTarget();
Load load = getLoad();

target.fire(load);

However, I might some day write a FtpLoad extends Load, and I don’t want to be able to fire a FtpLoad at an HttpTarget. So the essence of the above-referenced question was how do I do this, to which, the answer was generics.

However, as the answerer pointed out, this solution is a violation of the Liksov Substitution Principle. Other answerer/commenters seemed to indicate that what I was doing wasn’t necessarily good OOP practices.

So now I’m asking: how do I expose an API so that the Controller can be Load– and Target-agnostic, but still enforce that the proper Load subclass is fired on the proper Target type, all without violating Liskov Substitution?

And, if this is impossible to do (without violating Liskov), then what is the normal approach to a problem like this? Thanks in advance!

  • 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-11T17:35:32+00:00Added an answer on June 11, 2026 at 5:35 pm

    The easy way is to do some checking in your code to make sure the classes match up. You can use the instanceof keyword to check if it’s the correct class.

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

Sidebar

Related Questions

This one is similar to a question that I asked yesterday. However my concern
Yesterday in my interview I was asked this question. (At that time I was
This problem is related to This question I asked yesterday. Now it seems that
I asked this question yesterday got a pretty good answer but can't figure out
Yesterday, I asked this question and never really got an answer I was really
This question stems from this question that I asked yesterday. I've followed Theo's advice
This question is about a similar javascript scope problem that I asked yesterday .
This is a follow up to a question that was asked yesterday. I have
I posted a question up yesterday that asked for some help on an image
Yesterday I asked this general question about decimals and their internal precisions. Here 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.