About LSP [advanced oop theory]

Hi;

I understand

  • Derived classes must be substitutable for their base class.You should be able to replace the original class with sub class.
  • Child classes should never break the parent class’ type definitions.
  • Subtypes must be substitutable for their base types.

But I cannot related these to these items below. Can someone please explain them?

Thanks

Its signature must match that of its parent
Its preconditions (what to accept) must be the same or weaker
Its post conditions (what to expect) must be the same or stronger
Exceptions (if any) must be of the same type than the ones thrown by its parent

1 - For example is “signature” the type of variable? If so does it mean the “output” of a class’s method? Or the arguments that constructor accepts?

2 - What about pre and post conditions? I read somewhere that this code is not following the principles since the pre conditions are different!

class video_player
        {
            public function play()
                {

                }
        }

    class avi_video_player extends video_player
        {
            public function play($file)
                {
                    if($wrong_exception)
                            {
                                throw new Exception;
                            }
                }
        }

I understand that the child class throws an excpetion that parent doesn’t…but how is it pre condition?

3 - Exceptions? Does it simply mean that the methods in the child class that have overwritten the methods in parent should have the same exceptions as the method in the parent?

Thanks

Strange there is no edit button here n this page! I wanted to edit it to below:

Hi;

I understand

  • Derived classes must be substitutable for their base class.You should be able to replace the original class with sub class. In other words subtypes must be substitutable for their base type (same as above).

But I cannot fully understand these items below. Can someone please explain them?

Thanks

Child classes should never break the parent class's type definitions => Does this mean "Code to interface"?
Its signature must match that of its parent
Its preconditions (what to accept) must be the same or weaker
Its post conditions (what to expect) must be the same or stronger
Exceptions (if any) must be of the same type than the ones thrown by its parent

1 - For example is “signature” the type of variable? If so does it mean the “output” of a class’s method? Or the arguments that constructor accepts?

2 - What about pre and post conditions? I read somewhere that this code is not following the principles since the pre conditions are different!

class video_player
        {
            public function play()
                {

                }
        }

    class avi_video_player extends video_player
        {
            public function play($file)
                {
                    if($wrong_exception)
                            {
                                throw new Exception;
                            }
                }
        }

I understand that the child class throws an excpetion that parent doesn’t…but how is it pre condition?

3 - Exceptions? Does it simply mean that the methods in the child class that have overwritten the methods in parent should have the same exceptions as the method in the parent?

Thanks