Download presentation
Presentation is loading. Please wait.
Published byEmil Dixon Modified over 9 years ago
1
Sept 200592.3913 Ron McFadyen1 Class Diagram Begins as a conceptual or analysis class model and evolves to a design class model Used throughout the development process. More detail added as time goes by. A static view of classes – shows structure: data, operations, and associations.
2
Sept 200592.3913 Ron McFadyen2 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating() Customer getName() checkCreditRating()
3
Sept 200592.3913 Ron McFadyen3 Classes « Singleton » dbFacade Some classes are stereotyped: Later in the course we study the Singleton design pattern. Stereotyping dbFacade as singleton conveys substantial information about the class and its behaviour. Some methodologies have 3 stereotypes for “analysis” classes: boundary, control, entity
4
Sept 200592.3913 Ron McFadyen4 Classes Composite Abstract Classes An abstract class is one that is never instantiated. To indicate an abstract class, the class name is given in italics See last 2 examples
5
Sept 200592.3913 Ron McFadyen5 Attributes Joe: Customer Class instances An individual object (instance of a class) is shown with naming information underlined An unnamed customer : Customer A customer named Joe
6
Sept 200592.3913 Ron McFadyen6 Identifying classes … Main Success Scenario 1. Customer arrives at a POS checkout with goods and/or services to purchase 2. Cashier starts a new sale 3. Cashier enters item identifier 4. System records sale line item and presents item description, price, and running total Cashier repeats steps 3-4 until indicates done 5. System presents total with taxes calculated 6. Cashier tells customer the total and asks for payment 7. Customer pays and System handles payment 8.System logs the completed sale and sends sale and payment information to the external Accounting (for accounting and commissions) and inventory systems (to update inventory) 9.System presents receipt 10.Customer leaves with receipt and goods (if any)...
7
Sept 200592.3913 Ron McFadyen7 Attributes an object contains data which are defined as part of the Class definition examples: Students have names, addresses, etc; Courses have titles, descriptions, prerequisite information. Rectangle corner: Point Student name address Level of detail present will depend on whether you are in analysis or design, and your purposes at the time
8
Sept 200592.3913 Ron McFadyen8 Attributes To what degree is an attribute visible to other classes? Private – Public + Protected # Package ~ Student -name -address
9
Sept 200592.3913 Ron McFadyen9 Attributes Default values = Derived values / Multiplicity [ ] Ordering{ordered} Uniqueness{unique} Invoice -date:Date = today -/total: Currency -payments[0..*]: Currency Student -name -address[1..3] {unique}
10
Sept 200592.3913 Ron McFadyen10 Operations. What are the responsibilities of a class? What can it do? Visibility Parameters Signaturethe name, parameters, and return type of the operation Student +getName() +getGPA(term :Term, gpaType: String)
11
Sept 200592.3913 Ron McFadyen11 Associations correspond to verbs expressing a relationship between classes example a Library Member borrows a Copy of a Book Multiplicities we indicate via multiplicities the range of allowable cardinalities for participation in an association examples: 1, 1..*, 0..*, 1..3
12
Sept 200592.3913 Ron McFadyen12 Associations Names and roles you can name the relationship and indicate how to read it you can give role names for participating objects PersonCompany Works for 1..* 1 employer employee The role of a Person in this relationship The role of a Company in this relationship The name of the relationship and the direction for reading the name
13
Sept 200592.3913 Ron McFadyen13 Associations example: a Library Member borrows a Copy of a Book MemberBook * * borrower borrows
14
Sept 200592.3913 Ron McFadyen14 Associations example: An employee is supervised by an employee * 0,1 Employee reports to supervised supervisor A reflexive association
15
Sept 200592.3913 Ron McFadyen15 Objects Joe: Customer Class instances An individual object (instance of a class) is shown with naming information underlined An unnamed customer : Customer A customer named Joe
16
Sept 200592.3913 Ron McFadyen16 Objects Object state Consider an instance of a class Collectively, the specific attribute values and connections to other objects is known as the state of the object Analysis uncovers states of interest. These can be modeled using statechart diagrams
17
Sept 200592.3913 Ron McFadyen17 Generalization a generalization is a relationship between a general thing (the superclass or parent class) and a more specific kind of thing (the subclass or child class) example: a StaffMember is a specialized kind of LibraryMember a StudentMember is a specialized kind of LibraryMember LibraryMember StaffMemberStudentMember
18
Sept 200592.3913 Ron McFadyen18 Motivation for partitioning a class into subclasses: subclass has additional attributes of interest subclass has additional associations of interest subclass is operated on, handled, reacted to, or manipulated differently than the superclass or other subclasses
19
Sept 200592.3913 Ron McFadyen19 Generalization Multiple subclasses can be grouped to indicate they are related subclasses LibraryMember StaffMemberStudentMember It then becomes meaningful to consider certain constraints: complete, incomplete, disjoint, overlapping
20
Sept 200592.3913 Ron McFadyen20 Generalization Inheritance of attributes and behaviour: everything a LibraryMember can do, a StaffMember can do everything a LibraryMember can do, a StudentMember can do If a LibraryMember can borrow a book, so can a StaffMember and a StudentMember a StaffMember and a StaffMember have all the attributes the LibraryMember has, and possibly more Specialization: there are some things that a specialized class can do that a LibraryMember cannot LibraryMember StaffMemberStudentMember
21
Sept 200592.3913 Ron McFadyen21 Payment Amount: money Cash Payment Credit PaymentCheque Payment Sale Pays-for 1 1 Every payment, regardless of whether it is cash, credit, or cheque, has an Amount and it is associated with a Sale CreditCardCheque 1 1 1 *
22
Sept 200592.3913 Ron McFadyen22 The name Payment is italicized - meaning it is an abstract class An abstract class is a class that will never be instantiated; only its subclasses can exist If “Payment” was not in italics then a Payment could exist that is not a Cash, Credit, or Check payment Payment Amount: money Cash Payment Credit PaymentCheque Payment
23
Sept 200592.3913 Ron McFadyen23 What is the difference: Payment Unauthorized Payment Authorized Payment PaymentState Unauthorized StateAuthorized State Payment Is-in * 1
24
Sept 200592.3913 Ron McFadyen24 Aggregation and Composition both are associations used to denote that an object from one class is part of an object of another class HonoursProgrammeCourse An example of Aggregation: a course is part of an honours programme. The same module could be part of several honours courses Suppose the course “UML and Patterns” is part of both the “Software Engineering” and the “Computer Science” honours programmes **
25
Sept 200592.3913 Ron McFadyen25 Aggregation and Composition BoardSquare Composition is similar to, but stronger than aggregation. If you specify composition, then you are saying that one object owns its parts. A Board is made up of several Squares. A Square will belong to just one Board. If a Board is deleted, then its Squares are deleted too. What is the multiplicity at the composition end of the association? *
26
Sept 200592.3913 Ron McFadyen26 Aggregation and Composition InvoiceInvoiceLine Consider Invoices and their Invoice Lines Question: Is the association aggregation or composition? ? ? *
27
Sept 200592.3913 Ron McFadyen27 Aggregation and Composition SaleSalesLineItem Consider Sales and their SalesLineItems Is the association an aggregation or a composition? ? ? *
28
Sept 200592.3913 Ron McFadyen28 Aggregation and Composition Consider the General Calendar and its Course Specifications. Is the association an aggregation or a composition?
29
Sept 200592.3913 Ron McFadyen29 A composite is a group of objects in which some objects contain others; one object may represent groups, and another may represent an individual item, a leaf. Composite Pattern We will examine the composite pattern later in the course. At this time, we are many concerned with its structural aspect. Consider the class diagram that follows. What objects does it allow us to instantiate and how will they relate to one another?
30
Sept 200592.3913 Ron McFadyen30 MachComponent getMachineCount() Machine getMachineCount() MachComposite components: List getMachineCount() * PlantFloor 1 * 1 Composite Pattern Consider a UML class diagram for machines. Machines may be complex and contain other machines.
31
Sept 200592.3913 Ron McFadyen31 An object diagram illustrating the machine on floor 5 of the plant L1: Machine M1: MachComposite L2: Machine L7: MachineL4: Machine M9: MachComposite floor5 :Plantfloor Composite Pattern
32
Sept 200592.3913 Ron McFadyen32 The decorator pattern allows us to enclose an object inside another object. The enclosing object is called a decorator. The other object is the component, it is the decorated object. The decorator conforms to the interface of the enclosed component and so its presence is transparent to the components clients. The decorator forwards requests to the component, but may perform some processing before/after doing so. We will examine the decorator pattern later in the course. At this time, we are many concerned with its structural aspect. Consider the class diagram that follows. What objects does it allow us to instantiate and how will they relate to one another? Decorator Pattern
33
Sept 200592.3913 Ron McFadyen33 UML class diagram DecoratedReceipt print() receipt print() Decorator print() other() 1 sale timeOfDayproductCouponmoneySaved Decorator Pattern 11 How does the Decorator pattern differ from the Composite pattern? What would a typical object diagram look like?
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.