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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:55:36+00:00 2026-05-16T15:55:36+00:00

Can you provide scenarios when we inherit from a class, it works for a

  • 0

Can you provide scenarios when we inherit from a class, it works for a while, but then something else changes and introduces a bug?
I came up with the following situation:

  • to implement Rectangle-with-hole, we inherit from class Rectangle. In the constructor, we check that the hole is inside the rectangle
  • Later someone adds a new method Resize to class Rectangle. They don’t check if the hole is still inside.
  • After Resize, we can have Rectangle-with-holes with holes not inside rectangles, which is a bug.

What are the other problems I should be careful if I choose to use object inheritance in C#.

  • 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-16T15:55:37+00:00Added an answer on May 16, 2026 at 3:55 pm

    There are many ways a change to a base class can affect derived class behaviour. What if the author suddenly decided to make the class sealed for example?

    Like any interface it needs to be stable if consumers are to not require modification.

    The primary “rule” with inheritance is the Liskov Substition Principle. This states that the derived class should be substitutable for the base class or other classes derived from it.

    This case breaks this rule on the face of it, as a rectangle with a hole is not a rectangle.

    Usually it’s best to use interfaces to divide behaviour into sensible implementable chunks. Such interfaces are generally named with adjectives rather than nouns. For example, it makes sense for both a rectangle and a rectangle with a hole to be rendered, so an interface might be IRenderable. If it’s resizable you might have a IResizable, etc. These could be aggregated into an IShape, but you want to be careful that your definition of Shape defines just the behaviours in your problem domain.

    Directly deriving from another class can be dangerous as you’re then bound by the behaviour of that class. If you genuinely need to do that it can be best to extract the implementation you need into a common base class (e.g. Rectangle : RectangleImplementation, IShape).

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

Sidebar

Related Questions

I can provide more detail if necessary, but my question is basically thus: If
I do understand how Stack() and Stack<T> works, but I really can't see any
How would I create the following scenario that rails can provide for carrierwave, using
Hope the AWK gurus can provide a solution to my problem . I have
Thanks in advance for any help you can provide on this issue! I manage
The simplest example that I can provide for what I want to do is
Much like how the video tag can provide multiple source attributes so an mp4
I am looking for a library or database that can provide guesses about whether
I'm developing an application in .NET where the user can provide Regular Expressions that
What are three ways in which web applications can provide a stateful experience for

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.