190 likes | 362 Views
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?
E N D
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++) 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 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 class ResultsGenerator{ public void someMethod(Meet); public Meet someOtherMethod(); public void aThirdMethod(){ Meet aMeet; //Meet as a local object } }
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; } // // File Trial.java // package contests; import people.Gymnast; class Trial { private Gymnast performer; private TrialScoreList scores; public void addScore(RawScore); public Score score(); } // // File Event.java // package contests; import people.EventJudge; import people.Gymnast; import people.team; class Event { private Trial[] trialList; //This is a container for many trials //and probably needs more design work public void addJudge(EventJudge); public Score score(); public Score individualScore(Gymnast); public Score teamScore(Team); public String getTitle(); }
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.
Teaching Points • Implementation classes • Moving from design to code • Observer pattern