Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group
See Me Send me if you did not hand in Lab 1 or 2 –Include your full name –Tell me what group you have joined Hands up now –if you are not in a group –if you are in a group of 1 or 2 Kate Gregory2
DateWeekTopicHand OutDue BackTest 6-Sep-131Administrivia / Overview / Motivation, benefits of OO 13-Sep-132Use CasesLab 1: Use cases 20-Sep-133CRC Cards, collab graphsLab 2: CRC cardslab 1 5% 27-Sep-13 4start class diaglab 2 5% 4-Oct-135Finish class diag, AssociationsLab 3: Class Diag 11-Oct-136Inh & Polymorphism / midterm reviewlab 3 5% 18-Oct-137midtermMidterm 25% 25-Oct-13Reading Break 1-Nov-138Interaction diag / Design PatternsLab 4: Interaction Diag 8-Nov-139Good Design / Modules & Packages / Deployment and component diagrams /Metrics / SOLID Lab 5: Critiqueslab 4 5% 15-Nov-1310State diagrams / Activity diagrams / Summary and Conclusion / The Future 22-Nov-1311Critiquescritique lab (before class) 15% 29-Nov-1312Critiques TBDFinal ExamFinal 40%
Kate Gregory Current car: Car Objects are not Attributes On a class diagram, do not list attributes that are objects. Every person has a car, but not: Person Date of birth: Date travel () Current car: Car
Kate Gregory Associations A reference from one class to another is an association. Most relationships between classes are associations. –A person has a car. –An employee reports to a supervisor –An invoice is filled with items
Kate Gregory Objects are not Attributes Person Date of birth: Date travel () Car Mileage: int has
Kate Gregory Guidelines For Identifying Associations Association often appears as a verb in a problem statement and represents relationships between classes. –A pilot flies a plane. –A manager approves a transaction Other phrases include part of, next to, works for, contained in, etc. Verbs help to qualify an association, links for passing messages
Kate Gregory Common Association Patterns Location Association: next To, part of, contained in, ingredient of etc. –each employee is part of a department. Communication association: talk to, order to. –a customer places an order with an operator.
Kate Gregory Binary Association Notation On a class diagram, binary association is a line connecting two classes Both ends may be connected to the same class
Kate Gregory Links to pass Messages Listing Description MLS Agent Phone No writeInfo()
Kate Gregory Multiplicity Multiplicity specifies the number of instances of associated classes for each instance of this class. It is given for roles within associations, parts within compositions, repetitions, and other purposes. A number or range of numbers is written on each end of the line –lower bound.. upper bound. (0..1, 2..5 etc) –Single number (0, 1, etc) –* to indicate any number including 0 –1..* to indicate 1 and up
Kate Gregory Single Multiplicity Exactly one province for each city.
Kate Gregory Unlimited Multiplicity Sometimes there is no limit on the number of objects in the association. Any number of cities in a province
Kate Gregory Fixed Multiplicity Sometimes a object must be associated with a fixed number of other objects obvious or business rules state limited number (2 teams, 4 agents)
Kate Gregory Range of Multiplicity The most common range is 0 to 1: a single optional value The person either has an employer or does not: in this model no-one has more than one employer
Kate Gregory Range of Multiplicity Another popular range is 1 or more, represented as 1..*
Kate Gregory Range of Multiplicity Other than 0 to 1 and 1 or more, ranges are unusual. –A car has 2 to 5 doors… OK, but is “car door” likely to be an object? –A person has 0 to 5 credit cards… why can’t someone have 6? Push back when customers tell you ranges for relationships; make sure there’s a real business reason for the restriction and not some leftover from legacy software that couldn’t model reality
Kate Gregory Qualified Associations Sometimes multiplicity alone can’t describe the restrictions on a relationship –How many bank accounts does a customer have with each bank? –Can two of a customer’s accounts have the same number? As long as they’re with different banks
Kate Gregory Qualifier Bank Person account# *.
Kate Gregory OR Association An OR association indicates a situation in which only one of several potential associations may be in effect at one time for any single object. Person Company Car {or}
Kate Gregory Some Attributes Are Hard To Place Consider Company and Person –Person works for company –Where does the salary attribute go? Company? –Everyone makes the same salary Person? –All my jobs pay the same Salary is an attribute of the relationship
Kate Gregory Association Class An association class holds properties of the association An association class is shown as a class symbol attached by a dashed line to an association path. WorksFor Person employeremployee Company salary
Kate Gregory Association Class Association class is like a normal class with attributes and methods Adds extra information to the link House for SaleAgent Contract Expirydate commission
Kate Gregory Eliminate Unnecessary Associations Derived associations can be defined in terms of other associations. They are redundant; avoid.
Kate Gregory Eliminate Unnecessary Associations Implementation association. Defer implementation- specific associations to the design phase. –For example, if inventory is implemented by using an Array class, don’t show that relationship. Only show business relationships as determined by your analysis Ternary associations. Ternary or n-ary association is an association among more than two classes. Avoid. –Replace with a new class
Kate Gregory N-Ary Association Association among more than two classes. Difficult to understand GradeBook Student Course grade exam lab Year semester * * *
Kate Gregory Convert N-Ary Associations Create a class to represent the relationship GradeBook Student Course lab grade exam Year Session * * * *
Kate Gregory Association Class Replaces N-Ary House for SaleAgent Contract Expirydate commision Client * *
Kate Gregory Aggregation is a form of association representing a “part of” relationship. For example, players are part of a team. A hollow diamond is attached to the end of the path to indicate aggregation. “there is no single accepted definition of the differences between aggregation and association”, Fowler, UML Distilled, 1997 Aggregation
Kate Gregory Composition Composition is a form of aggregation with strong ownership to represent a component of a complex object. The “part” may belong to only one whole. –Compare a picture pasted into a Word document (composition) to a picture on a web page (aggregation) Cascading Destruction – can the part exist without the whole ? –A customer has a credit card. –A customer has a sales rep. –A window on the screen has a title, a scroll bar, menus, frame and so on.
Kate Gregory Composition Notation The UML notation for composition is a solid diamond at the “container” end of a path. Window TitleScroll barMenuFrame *
Kate Gregory Composition House for Salepicture
Kate Gregory Classes without Associations Sometimes a class is sitting all alone on the diagram Check the CRC cards –Collaborations generally can’t happen if objects can’t find each other –Those connections are associations –Sometimes connections are temporary, so don’t create an association –Think about the relationships between the real things these classes represent Look for words like “has”, “uses”, “owns”, “contains” A class without associations does not always need to be dropped –Another layer (e.g. user interface) may use it –Ask yourself if it’s really something in your system
Kate Gregory Cohesion and Coupling Only certain classes need to know about other classes -- this is coupling. The lower the coupling (number of connecting lines between classes) the better. Certain information should reside in the same location (class) – this is cohesion and makes classes self-sufficient. The higher cohesion, the better More on these in our metrics section later. Start to think about whether the classes you are shown exhibit high or low cohesion, and are tightly or loosely coupled.
Kate Gregory35 Remember what class diagrams are for Reference –Names of classes –Names of methods –Parameters to methods –Names of attributes Excellent summary of decisions Visual understanding of the system
Kate Gregory Next Week Inheritance Lab 3 Due –Think about concurrency issues –Rate your group members Read ahead if you like