Construction

Download Report

Transcript Construction

Construction
Lecture Oo21
Gymnastics System Example
Cont’d
Teaching Points



Implementation classes
Moving from design to code
Observer pattern
Review



What is a construction iteration?
What is the general process followed in
a construction iteration?
How can you design a new class that
does just-a-bit-more than parameterized
class?
How Class Attributes and
Operations are Implemented




Detailed designs provide enough detail
to imply guidance for implementation.
Names and detailed types for attributes
may be supplied
Names, signature (names and type of
parameters) and return type for
operations may be specified
Specifications provide detail on
semantics and algorithms
How Class Relationships are
Implemented

When using an Implementation
Perspective class relationships imply
some guidance for implementation.
Generalization (Inheritance)
class RawScoreList {
}
class TrialScoreList extends RawScoreList {
}
Realization
interface Enumeration {
public Object nextElement();
public bool hasMoreElements();
}
class TrialScoreList implements Enumeration {
public Object nextElement(){… }
public bool hasMoreElements(){… }
}
Binding (Instantiation of
Parameterized Class - C++)
T
RawScoreList
<<bind>>
List
(from Data Structures)
<RawScore>
Template<class T> class List{
};
// An example in a local object declaration
List<RawScore>
aRawScrLst(100);
// An example in a free store allocation
listPtr = new List<RawScore>(100);
// An example in an inheritance declaration
class TrailScoreList: public List<RawScore> {
};
Composition
-maxScore
Trial
double
-minScore
class Trial{
private double maxScore;
private double minScore;
}
Aggregation
class Trial{
private TrialScoreList scores; //Note: in this case we
//think of trial as being
//a container for scores
}
Association
class Trial{
private TrialScoreList scores; //Note: in this case we
//think of trial as being
//a peer object to the trial
//scores list
}
Dependency
Meet
ResultsGenerator
class ResultsGenerator{
public void someMethod(Meet);
public Meet someOtherMethod();
public void aThirdMethod(){
Meet aMeet;
}
}
//Meet as a local object
A Gymnastics System Example
You will have to open the PowerPoint file to get all the code:
//
// File RawScore.java
//
package dataStructures;
public class RawScore {
private Score value;
}
//
// File TrialScoreList.java
//
package contests;
import java.util.Vector;
class TrialScoreList extends Vector{
public RawScore min(){... }
public RawScore max(){... }
}
//
// File Gymnast.java
//
package people;
class Gymnast {
private Date birthdate;
private bool
gender;
private String
name;
Model-View-Controller

Problem: you want to be able to control
the state of a system and display the
state of the system, but you are not sure
how many displays/control mechanisms
will be needed and/or you are unsure of
the kind of displays/control mechanisms
that will be needed
MVC Structural Pattern
Model
+updates
+stateQuerries
Controller
View
+events
Note: in a pure MVC
architecture viewers do not talk
to controllers
Observer Pattern

Problem
– A common side-effect of partitioning a
system into a collection of cooperating
classes is the need to maintain consistency
between related objects.
– You don't want to achieve consistency by
making the classes tightly coupled,
because that reduces their reusability.
Observer Pattern

Solution
– Define a one-to-many dependency
between objects so that when one object
changes state, all its dependents are
notified and updated automatically.
Observer Pattern (Structure)
Observer Pattern (Interactions)
Teaching Points



Implementation classes
Moving from design to code
Observer pattern