Google
 

 

up previous next contents
Up: 1. Day 1: Object-Oriented Previous: 1.2 Why OO? Next: 1.4 UML summary   Contents

Subsections

1.3 Introduction to OO concepts

What does it mean to be ``object-oriented''? The ``big three'' concepts are encapsulation, polymorphism, and inheritance, but the text ``Fundamentals of Object-Oriented Design in UML'' [12] specifies that the following criteria are necessary for a language to be considered object oriented.

  1. Encapsulation - the grouping of related ideas into unit. Encapsulating attributes and behaviors.
  2. Inheritance - a class can inherit its behavior from a superclass (parent class) that it extends.
  3. Polymorphism - literally means ``many forms''.
  4. Information/implementation hiding - the use of encapsulation to keep implementation details from being externally visible.
  5. State retention - the set of values an object holds.
  6. Oject identity - an object can be identified and treated as a distinct entity.
  7. Message passing - the ability to send messages from one object to another.
  8. Classes - the templates/blueprints from which objects are created.
  9. Genericity - the construction of a class so that one or more of the classes it uses internally is supplied only at run time.
  10. Test here
  11. More testing here

1.3.1 Encapsulation

The grouping of related items into one unit.

  • One of the basic concepts of OO.
  • Attributes and behaviors are encapsulated to create objects.
  • OO modeling is close to how we perceive the world.
  • Implementation details are hidden from the outside world. We all know how to use a phone, few of us care how it works.
  • The packaging of operations and attributes representing state into an object type so that state is accessible or modifiable only through the objects' interface
  • Encapsulation lets builders of objects reuse already-existing objects, and if those objects have already been well-tested, much larger and more complex systems can be created.

1.3.2 Inheritance

  • A subclass is derived from a superclass. An Employee is a Person.
  • The subclass inherits the attributes and behavior of the superclass.
  • The subclass can override the behavior of the superclass.
  • Notice the use of the ``Is-A'' phrase to describe inheritance.
  • Inheritance promotes re-use.

1.3.3 Polymorphism

  • Literally means ``many forms''.
  • A method can have many different forms of behavior.
  • Commonly used between a set of classes that have a common superclass.
  • The sender of a message does not have to know the type/class of the receiver.
  • A single operation or attribute may be defined upon more than one class and may take on different implementations in each of those classes.
  • An attribute may point to different objects at different times.

1.3.4 Abstraction with objects

  • Abstraction: the act of identifying software artifacts to model the problem domain.
  • Classes are abstracted from concepts.
  • This is the first step in identifying the classes that will be used in your applications.
  • Better to have too many classes than too few. (?)
  • When in doubt, make it a class. (?)

1.3.5 Message passing

  • Objects communicate by sending messages.
  • Messages convey some form of information.
  • An object requests another object to carry out an activity by sending it a message.
  • Most messages pass arguments back and forth.
  • Meilir Page-Jones defines three types of messages[12]:
    1. Informative - send information for the object to update itself.
    2. Interrogative - ask an object to reveal some information about itself
    3. Imperative - take some action on itself, or another object
  • Grady Booch defines four types of messages[4]:
    1. Synchronous - receiving object starts only when it receives a message from a sender, and it is ready.
    2. Balking - sending object gives up on the message if the receiving object is not ready to accept it.
    3. Timeout - sending object waits only for a certain time period for the receiving object to be ready to accept the message.
    4. Asynchronous - sender can send a message to a receiver regardless of whether the receiver is ready to receive it.