Thinking of classes as blueprints for machines helps

This preview shows page 5 - 8 out of 12 pages.

Thinking of classes as blueprints for “machines” helps clarify the advantages of the OO approach. To a user, a machine is a “black box” with inputs, outputs and behavior – but one can’t see inside. There is a large and complex CS literature on this, but we can take a simplistic view here.
Image of page 5

Subscribe to view the full document.

Abstract Machines, cont. In OO terms Inputs to the machine come from the parameters passed to setter methods Outputs come in the form of return values from getter methods or (shudder) side-effects. Behavior is the program logic that maps a sequence of inputs to a sequence of outputs. Objects have attributes (member variables) held internally Objects have state (this tracks sequence and allows a sequence of inputs to result in a sequence of outputs). They also may generate exceptions.
Image of page 6
Abstract Machines, cont. Meyer (read the article) talks about: Preconditions Postconditions Invariants Consider a deliverSoda( ) method for our hypothetical soft-drink machine: What must be true for this method to succeed (precondition)?
Image of page 7

Subscribe to view the full document.

Image of page 8
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern