Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: LSP: weaken pre-condition and strengthen post-condition

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default LSP: weaken pre-condition and strengthen post-condition

    The code is attached in the image.

    So the question is whether an object of type OneLeggedRobot is subsitutable for its supertype Robot.

    The answer key said the answer was no because the subtype (OneLeggedRobot) has a stronger precondition than Robot.

    But my class notes says that the precondition is weakened when the subtype method requires less from its caller than the supertype method.

    Going by my class notes I thought the precondition was weakened the subtype needs direction to be 1 or 3 and the supertype needs direction to be 1,2 or 3. In other words if the precondition of the supertype holds, the precondition of the subtype will also hold.

    And what about the postcondition? I think the subtype has a weaker post-condition than the supertype because the supertype does more (it includes a specified direction for 2). Is that correct or am I completely backwards?
    Attached Images Attached Images


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: LSP: weaken pre-condition and strengthen post-condition

    More people will be able to read the code if it's posted in the thread, not as an image.

    Do you have a java programming question? The post doesn't seem to have anything about java in it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. For Loop with condition
    By mindful314 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 11th, 2014, 04:00 PM
  2. [SOLVED] If condition not working.
    By Variumzky in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 29th, 2013, 01:03 AM
  3. condition number? what is it?
    By gspease839 in forum Algorithms & Recursion
    Replies: 2
    Last Post: February 9th, 2013, 10:00 PM
  4. Have Problem with if condition...Please Help me...
    By Jalpesh Ruparel in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2011, 01:54 AM
  5. Waiting until condition
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: October 22nd, 2010, 09:24 AM