kate gregory week 5 static object model –attributes –methods –associations –visibility lab 3...
TRANSCRIPT
![Page 1: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/1.jpg)
Kate Gregory
Week 5
• Static Object Model– Attributes– Methods – Associations– Visibility
• Lab 3 available– Rating your group
![Page 2: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/2.jpg)
See Me
• Send me email 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 Gregory 2
![Page 3: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/3.jpg)
Date Week Topic Hand Out Due Back Test
6-Sep-13 1 Administrivia / Overview / Motivation, benefits of OO
13-Sep-13 2 Use Cases Lab 1: Use cases
20-Sep-13 3 CRC Cards, collab graphs Lab 2: CRC cards lab 1 5%
27-Sep-134 start class diag lab 2 5%
4-Oct-13 5 Finish class diag, Associations Lab 3: Class Diag
11-Oct-13 6 Inh & Polymorphism / midterm review lab 3 5%
18-Oct-13 7 midterm Midterm 25%
25-Oct-13 Reading Break
1-Nov-13 8 Interaction diag / Design Patterns Lab 4: Interaction Diag
8-Nov-13 9 Good Design / Modules & Packages / Deployment and component diagrams /Metrics / SOLID
Lab 5: Critiques lab 4 5%
15-Nov-13 10 State diagrams / Activity diagrams / Summary and Conclusion / The Future
22-Nov-13 11 Critiques critique lab (before class) 15%
29-Nov-13 12 Critiques
TBD Final Exam Final 40%
![Page 4: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/4.jpg)
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
![Page 5: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/5.jpg)
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
![Page 6: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/6.jpg)
Kate Gregory
Objects are not Attributes
Person
Date of birth: Date
travel ()
Car
Mileage: inthas
![Page 7: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/7.jpg)
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
![Page 8: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/8.jpg)
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.
![Page 9: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/9.jpg)
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
Company PersonworksFor
employer employee
Person
marriedTo
![Page 10: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/10.jpg)
Kate Gregory
Links to pass Messages
Listing
Description
MLS
Agent
Phone No
writeInfo() writeInfo()
![Page 11: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/11.jpg)
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
![Page 12: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/12.jpg)
Kate Gregory
Single Multiplicity
• Exactly one province for each city.
![Page 13: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/13.jpg)
Kate Gregory
Unlimited Multiplicity
• Sometimes there is no limit on the number of objects in the association.
• Any number of cities in a province
![Page 14: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/14.jpg)
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)
Car W heels4
![Page 15: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/15.jpg)
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
![Page 16: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/16.jpg)
Kate Gregory
Range of Multiplicity
• Another popular range is 1 or more, represented as 1..*
![Page 17: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/17.jpg)
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
![Page 18: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/18.jpg)
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
![Page 19: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/19.jpg)
Kate Gregory
Qualifier
Bank
Person
account#
*
.
![Page 20: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/20.jpg)
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}
![Page 21: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/21.jpg)
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
![Page 22: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/22.jpg)
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
Personemployer employee
Company
salary
![Page 23: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/23.jpg)
Kate Gregory
Association Class• Association class is like a normal class with
attributes and methods
• Adds extra information to the link
House for Sale Agent
ContractExpirydate
commission
![Page 24: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/24.jpg)
Kate Gregory
Eliminate Unnecessary Associations
• Derived associations can be defined in terms of other associations. They are redundant; avoid.
![Page 25: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/25.jpg)
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
![Page 26: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/26.jpg)
Kate Gregory
N-Ary Association• Association among more than two classes. • Difficult to understand
GradeBook
StudentCourse
gradeexamlab
Year
semester
*
*
*
![Page 27: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/27.jpg)
Kate Gregory
Convert N-Ary Associations• Create a class to represent the relationship
GradeBook
StudentCourse
labgradeexam
Year
Session
*
*
* *
![Page 28: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/28.jpg)
Kate Gregory
Association Class Replaces N-Ary
House for Sale AgentContractContractExpirydate
commision
Client
**
![Page 29: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/29.jpg)
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
P la y e rc la ss
T e a m1 *c o n sis tO f
![Page 30: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/30.jpg)
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.
![Page 31: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/31.jpg)
Kate Gregory
Composition Notation
• The UML notation for composition is a solid diamond at the “container” end of a path.
Window
Title Scroll bar Menu Frame
0..21
1 *
![Page 32: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/32.jpg)
Kate Gregory
Composition
House for Sale picture
![Page 33: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/33.jpg)
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
![Page 34: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/34.jpg)
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.
![Page 35: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/35.jpg)
Kate Gregory 35
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
![Page 36: Kate Gregory Week 5 Static Object Model –Attributes –Methods –Associations –Visibility Lab 3 available –Rating your group](https://reader036.vdocument.in/reader036/viewer/2022070411/56649f535503460f94c77350/html5/thumbnails/36.jpg)
Kate Gregory
Next Week
• Inheritance
• Lab 3 Due– Think about concurrency issues– Rate your group members
• Read ahead if you like