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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:06:26+00:00 2026-05-24T17:06:26+00:00

In the real world a square is a rectangle, but to a program this

  • 0

In the real world a square is a rectangle, but to a program this is not the case(LSP principle). is it considered an anti-pattern / poor programming to create a blank interface to logically group objects together? My thought is with a blank interface it would be impossible to violate the LSP at the level directly beneath it. Contrived example below.

Abstract class Canine{ }  

Dog extends Canine {…} 

Wolf extends Canine {…}
  • 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-24T17:06:28+00:00Added an answer on May 24, 2026 at 5:06 pm

    Depends what it’s for.

    An empty interface imposes no syntactic requirements, since there are no methods to implement.

    But the interface might be documented to impose semantic requirements, especially if Canine itself inherits from Canoidea or Carnivora or whatever. This makes the empty interface potentially useful since it provides guarantees of its own. All Carnivora have ears[*], but Canoidea are characterized in part by some property of their ears that isn’t easily expressed as simply as adding a method, so implementing the interface becomes a promise: “in addition to being a Carnivora, my ears behave like that”.

    That means it’s no longer impossible to violate the LSP. You could accidentally write a subclass with an overridden function that returns 12, which is permitted for Carnivora, but the semantics of Canine say that it won’t return more than 10.

    Interfaces that add only semantics aren’t necessarily great to work with, since there are certain mistakes that it’s easy to make. An example is the difference between InputIterator and ForwardIterator in C++ (although of course those are template concepts, not inherited interfaces). If you tag your class with the wrong one, the compiler will never notice. But if you tag your class with RandomAccessIterator when really it’s only a ForwardIterator, then the compiler will notice, when someone tries to use operator+ on it, since operator+ is part of RandomAccessIterator but not ForwardIterator.

    An empty interface with no semantics is meaningless, and hence probably useless. The only use for it I can think of is as a kind of variant – some dodgy code could test whether the object is an instance of “Dog” or “Wolf” (or something else), and do different things accordingly. That’s probably not a good use since it’s probably not good code in the first place. You might as well use an ultimate superclass like Object, if available, since either way the code is going to have to cope with types that it doesn’t recognise and can’t handle. “What on earth is a Fox, I can’t use a Fox here” is no better or worse than “What on earth is a Vector, I can’t use a Vector here”, so if what you understand is dogs and wolves, there’s no real advantage to accepting a Canine compared with accepting an Object. They’re both variants which allow Dogs, Wolves, plus anything else someone chooses to slot into the hierarchy.

    [*] Yes, even seals. They just don’t have pinnae.

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

Sidebar

Related Questions

Reading Real world Haskell i found some intresting question about data types: This pattern
This problem came up in the real world, but I've translated it into a
The one-liner should: solve a real-world problem not be extensively cryptic (should be easy
While reading Real world Haskell I came up with this note: ghci> :info (+)
What real-world projects would you suggest looking through the sources? As I'm learning Java
What are real-world problems where a recursive approach is the natural solution besides depth-first
I'm sampling a real-world sensor, and I need to display its filtered value. The
NOTE: EDITED The real-world situation is a series of events that each have two
I'm currently on chapter 4 of Real World Haskell, and I'm trying to wrap
How would I go about creating a real world form creation class that I

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.