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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:17:21+00:00 2026-05-11T22:17:21+00:00

I am new to design and learning the design principles. It says deriving square

  • 0

I am new to design and learning the design principles.

It says deriving square from rectangle is a classic example of violation of Liskov’s Substitution Principle.

If that’s the case, what should be the correct design?

  • 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-11T22:17:21+00:00Added an answer on May 11, 2026 at 10:17 pm

    I believe the reasoning is something like this:

    Let’s say you have a method that accepts a rectangle and adjusts its width:

    public void SetWidth(Rectangle rect, int width)
    {
        rect.Width = width;
    }
    

    It should be perfectly reasonable, given what a rectangle is, to assume that this test would pass:

    Rectangle rect = new Rectangle(50, 20); // width, height
    
    SetWidth(rect, 100);
    
    Assert.AreEqual(20, rect.Height);
    

    … because changing a rectangle’s width does not affect its height.

    However, let’s say you’ve derived a new Square class from Rectangle. By definition, a square has height and width always equal. Let’s try that test again:

    Rectangle rect = new Square(20); // both width and height
    
    SetWidth(rect, 100);
    
    Assert.AreEqual(20, rect.Height);
    

    That test will fail, because setting a square’s width to 100 will also change its height.

    Thus, Liskov’s substitution principle is violated by deriving Square from Rectangle.

    The “is-a” rule makes sense in the “real world” (a square is definitely a kind of rectangle), but not always in the world of software design.

    Edit

    To answer your question, the correct design should probably be that both Rectangle and Square derive from a common “Polygon” or “Shape” class, which does not enforce any rules regarding width or height.

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

Sidebar

Related Questions

I am starting to design a new application and what I am wondering is
New to silverlight. Traditionally if I were to design a wizard-like process where a
For my brand new ORM ( chibi-ORM ) I face a design decision. I'm
We're working now on the design of a new API for our product, which
What do I have to consider in database design for a new application which
I am new to this. I want to design an image gallery in my
I am new to C# and .NET programming. I want to design an application
What is your best practical user-friendly user-interface design or principle? Please submit those practices
I am relatively new to design patterns and am playing around with the GangOfFour
I'm new to database design and I considering implementing something that will be time

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.