CS 4773 Object Oriented Systems Terminology and UML
Read: Core Java 1, Chapter 4
Terminology
- class - a template or blueprint from which objects are made
- interface - a group of constants and method declarations that define the
form of a class but do not provide any implementation of the methods.
- instantiation - constructing an instance of a class
- encapsulation - hiding implementation details
- field - an instance variable or data member of an object.
- local variable - a variable defined inside a method
- method - the implementation of an operation which is defined by an
interface or class.
- state of an object - the current values of all of the fields
- extends - a class extends another
- object - an instance of a class
- constructor - used to instantiate an object
- inheritance - a mechanism that allow a class or interface to be defined
as a specialization of another more general class or interface.
- subclass - a specialization of another more general class.
- superclass - a generalization of another class.
- dependency - a using relationship in which a change to an independent
object may affect another dependent object.
- association - a specialized dependency where a reference to another class
is stored.
- property - information about the current state of a component.
Properties can be thought of as named attributes of a component that a
user program can read (get) or write (set).
- static - having class scope
- mutable object - an object whose state can change
Structured Programming:
Design procedures to solve a problem. (verbs)
Then decide on the data structures for storing the data.
After you identify the tasks to be performed you can use either top-down or
bottom-up design (or a combination)
top down: stepwise refinement: break the problem in to subtasks.
bottom up: write procedures to solve simple tasks and then combine them.
Object Oriented Design:
Think in terms of objects: nouns
Each object is responsible for carrying out a set of related tasks.
An object should never directly manipulate the data of another object.
It should not expose data for other object to manipulate.
First isolate the classes. Only then do you think about methods.
Each method is associated with the class that is responsible for the operation.
Important characterists of an object:
- behavior - what can you do with the object (public methods)
- state - values of all fields
- identity - can distinguish between others with the same behavior and state
Relationships between classes:
- Dependence: uses-a
- Aggregation: has-a
- Inheritance: is-a
Introduction to UML class diagrams
UML class diagrams show relationships between classes.
UML Notation from Design Patterns Explained, page 38.
There are 2 types of has-a relations: composition and aggregation
Note that the distinction between aggregation and composition is subtle
and often no distinction is made.
Composition: contained object is an intrinsic part of the containing object
    Usually, the contained object has the same lifetime as the
containing object.
Aggregation: contained object is not part of the containing object
    Usually, the contained object has an existence independent of the containing object
Examples:
- an airport has airplanes (aggregation)
- an airport has runways (composition)
- a car has tires (composition)
- a car has passengers (aggregation)
Class A has-a class B if there is a field of B in A.
This is different from uses-a.
Typically Class A uses-a class B if B is used in a method of A.
    May be a parameter
    May be a local variable of a method
    May be created with new
Figures 2-3 and 2-4 from Design Patterns Explained, pages 39 and 40.
Some classes diagrams for the TimeTest application.
These diagrams are from JBuilder Enterprise.
- Associations (has-a: composition and aggregation) are shown on
the left of the central class.
- Dependencies (uses-a) are shown on the right of the central class.
- Extended classes (is-a) and implemented interfaces appear above the
central class.
- Extending and implementing interfaces appear below the central class.
Programming in Java
- Fields should always be private and accessed through methods.
You should break this rule only if you can provide good justification.
- Fields and local variables should be initialized.
Java has rules for default initialization of fields, but you should
not rely on them.
- Avoid using local variables that override fields.
- Do not write accessor methods that return references to
mutable objects.
Examples of some immutable objects: Integer, String
Examples of some mutable objects: arrays
- Make all methods private that will not be accessed from outside the class.
Class Project Introduction
Design an editor to edit records of (so far) undisclosed type
- Records are stored in a file (possibly remotely)
- Multiple users can access either locally or remotely - synchronization issues
- Friendly user interface (GUI)
- Determine the major classes, their functionality (public methods) and interactions
- Use informal UML-like diagrams