Review of 115 material (Fall 2007)
- Classes & Objects
- The basic building blocks of object-oriented (OO) programs
are objects.
- Objects have properties and behaviors.
- Objects are instances of classes.
- At runtime an OO program consists of a system of objects
which communicate with one another by sending messages to each
other.
- UML class diagrams
- UML class diagrams are used to show selected aspects of
the design of a program.
- UML class diagrams consist of boxes (representing classes
and interfaces) and lines between boxes (representing
relationships between classes).
- Relationships
- has-a/composition
This is typically a relationship between two classes. As
we have gotten to know this relationship, if A has-a B then A
declares an instance variable of type B, creates an instance
of B in its constructor, and assigns that new instance to the
instance variable. This relationship is appropriate to model
situations where one object models an integral part of another
object (such that the lifetime of the part is determined by
the lifetime of the whole). This can be a relationship
between a class C and an interface I if C declares an instance
variable of type I but creates an instance of a class which
implements I in the constructor, and assigns that new instance
to the instance variable.
- knows-a/association
This is typically a relationship between two
classes. As we have gotten to know this relationship, if A
knows-a B then A declares an instance variable of type B, and
provides some mechanism by which that instance variable can be
assigned an instance of type B (either via a parameter in the
constructor or by providing a mutator). In particular A has
no responsibility to create an instance of B. The lifetimes
of A and B can be entirely independent of each other. As with
the has-a relationship this can be a relationship between a
class C and an interface I. If so, C declares an instance
variable of type I but assigns to the instance variable an
instance of a class which implements I.
- uses-a/dependency
We have used this relationship as a bit of a
catch-all relationship - any relationship between classes
which isn't a has-a, knows-a, is-a or implements relationship.
Typically we will use this if there is some mention of a
class/interface in a class, but no instance variable is
involved. In effect this means that either no variable is
involved (an instance of a class is simply created) or a local
variable (possibly a parameter) is used to store a reference
to an object.
- is-a/inheritance/generalization
This relationship is expressed in Java using the
"extends" keyword in the class header. It is a relationship
either between two classes or between two interfaces.
- implements/realization
This relationship is expressed in Java using the
"implements" keyword in the class header. It is a
relationship between a class and an interface.
- Design patterns
- One way to think of design patterns is as "best practices"
solutions to commonly occuring problems.
- Design patterns we saw this semester:
- Composite
- Null object
- Observer (Listener)
- Singleton
- State
- Strategy
- Polymorphism
- Different objects of same (super)type respond to same
message in different ways (appropriate to their actual type)
- For example, if you pull the tail of a dog and a cat they
will respond differently (dog will growl and bark, the cat
will hiss and scratch). Same message, different
response. Polymorphism.
- Recall the Bacterium lab. The different behaviors caused
the Bacteria to do different things. Same message, different
response. Polymorphism.
- Collections
- java.util.HashSet>E< and java.util.ArrayList>E<
- add and remove methods
- Collections.shuffle method (requires a List)
- Mappings
- implicit mappings (give formula for computing range value
given domain value)
- functions (e.g. implemented as non-void methods)
- explicit mappings (list pairs of values in mapping)
- java.util.HashMap>K,V<
- not a java.util.Collection
- put, get, remove, containsKey methods
- Primitives
- Especially boolean, int and double
- finiteness of representations
- operators
- Control structures
- selection: if, if-else
- repetition: while, foreach
- Equality testing
Carl G. Alphonce
Last modified: Thu Dec 6 22:06:53 EST 2007