4

What's the OO principle that states (in sum):

A base object should have no knowledge of its subtypes.

I thought it was Liskov Substitution but after reading that wikipedia article I don't believe I'm correct. Thanks in advance!

Telastyn
110k29 gold badges248 silver badges373 bronze badges
asked Dec 8, 2013 at 12:02
3
  • It might have been a reference to "Program to an interface, not to an implementation" (which means not to bypass an interface or to make assumptions about the implementation that the interface doesn't make explicit), or it might have been a reference to the "extension points" (specific places where the behavior of a base class is intended to be extended, i.e. don't modify base class behaviors that aren't meant to be modified.) Posted as comment since I don't have concrete reference. Commented Dec 8, 2013 at 12:08
  • 2
    When you say "children" do you mean other objects to which it holds references, or do you mean instances of subclasses of parent's class ? If the latter, then yes, a given instance of a class should not be aware (and, on some platforms, physically can't be aware) of whatever subclasses of it (and instances of those subclasses) exist. Commented Dec 8, 2013 at 12:27
  • Thanks @ShivanDragon (+1) - yes I meant the latter, but was wondering what the name of the principle is, not the principle itself! Thanks again! Commented Dec 8, 2013 at 12:42

2 Answers 2

4

This probably comes under dependency inversion.

The parent is a higher level abstraction than its child so it cannot be dependant on the child's implementation. It cannot know that a lower level abstraction exists or else it would by definition be dependant on it..

answered Dec 8, 2013 at 12:56
7

It is the Open Closed Principle.

Classes should be open to extension, but closed to modification.

If a class knows about its subtypes, that implies you can't just add one (extend the class) without modifying the base type (which should be prohibited).

answered Dec 8, 2013 at 13:53
2
  • 1
    Dogmatism will kill us all one day. Subclasses are sometimes an implementation detail, and you may very well have a parent class that knows about its subtypes. Commented Dec 8, 2013 at 21:49
  • 1
    @tibo - Yes, there are very few absolutes in the world. If all of the types are internal, that becomes less offensive - but I can't think of a good example where this couldn't be done more cleanly another way. Commented Dec 8, 2013 at 21:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.