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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:41:40+00:00 2026-06-11T00:41:40+00:00

1) Does LSP also apply to interfaces, meaning that we should be able to

  • 0

1) Does LSP also apply to interfaces, meaning that we should be able to use a class implementing a specific interface and still get the expected behavior?

2) If that is indeed the case, then why is programming to an interface considered a good thing ( BTW- I know that programming to an interface increases loose coupling ), if one of the main reasons against using inheritance is due to risk of not complying to LSP? Perhaps because:

a) benefits of loose coupling outweight the risks of not complying to LSP

b) compared to inheritance, chances that a class ( implementing an interface ) will not adher to LSP are much smaller

thank you

  • 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-11T00:41:41+00:00Added an answer on June 11, 2026 at 12:41 am

    Does LSP also apply to interfaces, meaning that we should be able to use a class implementing a specific interface and still get the expected behavior?

    LSP applies to the contract. The contract may be a class or an interface.

    If that is indeed the case, then why is programming to an interface considered a good thing ( BTW- I know that programming to an interface increases loose coupling ), if one of the main reasons against using inheritance is due to risk of not complying to LSP? Perhaps because:

    It’s not about an interface or a class. It’s about a violation of the contract. Let’s say that you have a Break() method in a IVehicle (or VehicleBase). Anyone calling it would expect the vehicle to break. Imagine the surprise if one of the implementations didn’t break. That’s what LSP is all about.

    a) benefits of loose coupling outweight the risks of not complying to LSP

    ehh?

    b) compared to inheritance, chances that a class ( implementing an interface ) will not adher to LSP are much smaller

    ehh?

    You might want to read my SOLID article to understand the principle better: http://blog.gauffin.org/2012/05/solid-principles-with-real-world-examples/

    Update

    To elaborate – with inheritance virtual methods may consume private members, to which subclasses overriding these virtual methods don’t have access to.

    Yes. That’s good. members (fields) should always be protected ( = declared as private). Only the class that defined them really know what their values should be.

    Also, derived class inherits the context from parent and as such can be broken by future changes to parent class etc.

    That’s a violation of Open/closed principle. i.e. the class contract is changed by changing the behavior. Classes should be extended and not modified. Sure, it’s not possible all the time, but changes should not make the class behave differently (other than bugfixes).

    Thus I feel it’s more difficult to make subclass honour the contract than it is to make class implementing an interface honour it

    There is a common reason to why extension through inheritance is hard. And that’s because the relationship isn’t a true is-a relationship, but that the developer just want to take advantage of the base class functionality.

    That’s wrong. Better to use composition then.

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

Sidebar

Related Questions

Does anyone know of a Mootools script that provides nested sortable but also works
Does using virtual methods violates LSP ( L part of SOLID principles) or there
Does anyone know how I can directly access a function from a PHP class
Does anyone know of any existing solutions using javascript that can parse a crontab
Does the Date object in Javascript ever use a non-Gregorian calendar? The MDN and
does anyone know if iOS Simulator (that goes with XCode) support any kind of
Does anyone out there know if it is possible to use sharding with a
Today somebody told me that interface implementation in C# is just Can-Do relationship, not
Does anyone have any recommendations of tools that can be of assistance with moving
Does the Flex compiler pass a version number that's accessible to conditional compilation? The

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.