Presentation is loading. Please wait.

Presentation is loading. Please wait.

2007ACS-3913 Ron McFadyen1 Class Diagram See Schaum’s UML Outline, especially chapters 4, 5, 6, 7.

Similar presentations


Presentation on theme: "2007ACS-3913 Ron McFadyen1 Class Diagram See Schaum’s UML Outline, especially chapters 4, 5, 6, 7."— Presentation transcript:

1 2007ACS-3913 Ron McFadyen1 Class Diagram See Schaum’s UML Outline, especially chapters 4, 5, 6, 7

2 2007ACS-3913 Ron McFadyen2 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating() Customer getName() checkCreditRating() Class name attributes operations attributes Class name

3 2007ACS-3913 Ron McFadyen3 Class « Singleton » dbFacade Some classes are stereotyped: Later in the course we study the Singleton design pattern. Some methodologies have 3 stereotypes for “analysis” classes: boundary, control, entity

4 2007ACS-3913 Ron McFadyen4 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

5 2007ACS-3913 Ron McFadyen5 Attributes To what degree is an attribute visible to other classes? Private – Public + Protected # Package ~ Student -name -address

6 2007ACS-3913 Ron McFadyen6 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}

7 2007ACS-3913 Ron McFadyen7 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)

8 2007ACS-3913 Ron McFadyen8 Associations correspond to verbs expressing a relationship between classes example a Library Member borrows a Copy of a Book Navigability A directed association show that messages will be sent in that direction Multiplicities we indicate via multiplicities the range of allowable cardinalities for participation in an association examples: 1, 1..*, 0..*, 1..3

9 2007ACS-3913 Ron McFadyen9 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

10 2007ACS-3913 Ron McFadyen10 Associations example: A duck uses a flying behavior DuckFlyBehavior 1 uses

11 2007ACS-3913 Ron McFadyen11 Associations example: An employee is supervised by an employee * 0,1 Employee reports to supervised supervisor A reflexive association: an instance of this association involves two Employee objects (two objects from the same class).

12 2007ACS-3913 Ron McFadyen12 Inner Class See Head First, Chapter 2, page 73 Other sources: Applying UML and patterns; Ch 26 Object-oriented design & patterns; Ch 5 SwingObserverExample AngelListener Angel listens to DevilListener Devil listens to + + +It is common to use to indicate an inner class

13 2007ACS-3913 Ron McFadyen13 Navigability The association below is directed. The arrow indicates the direction in which messages are sent. Note this means that a duck will “know” its flying behaviour. In the implementation of a duck there is need for an attribute that is a reference to a flying behaviour object. DuckFlyBehavior 1 uses

14 2007ACS-3913 Ron McFadyen14 Navigability: An association line with a navigability adornment indicates that an object of one class (A) is connected uni-directionally to an object of another class (B) An object of class A can navigate to an object of class B. I.e. an object of class A needs to know the B object, but not the other way around. An instance of A can send a message to an instance of B, the instance can respond, but doesn’t initiate. An association line that has no specific navigation indicated, is considered to be bi-directional In an OO language, an A will have an attribute that references a B instance A b: B B

15 2007ACS-3913 Ron McFadyen15 Association Class Business rule: a person contracts their services to a company Association Class: a modeling element that is both an association and a class. It has attributes, operations, multiplicities, etc. It can participate in other relationships. Note the dashed line. Company Person Contract startDate **

16 2007ACS-3913 Ron McFadyen16 Many to many associations likely candidate for an Association Class Limitation: each company object can be associated to a person object only once. If we wanted to provide for a person to be contracted to the same company more than once, we would need to promote Contract to be a regular class. How do we model this? Company Person Contract startDate **

17 2007ACS-3913 Ron McFadyen17 Reflexive Association An association involving the same class more than once. marries Person 1 1 marries Person * * ?

18 2007ACS-3913 Ron McFadyen18 Reflexive Association An association involving the same class more than once. comprises Part * *

19 2007ACS-3913 Ron McFadyen19 Interfaces An interface is special type of class that cannot be instantiated. An application can never instantiate an interface. An interface defines a set of public attributes and operations that some class must use (depends on) There is no behaviour defined, no method coded Some other class inherits the interface and provides the implementation (generalization, inheritance)

20 2007ACS-3913 Ron McFadyen20 Interfaces > FlyBehavior FlyNoWay fly() These classes implement the fly operation FlyWithWings fly() The interface named FlyBehavior comprises the fly operation

21 2007ACS-3913 Ron McFadyen21 Abstract Classes An abstract class is a special type of class in a class hierarchy that cannot be instantiated. An application can never instantiate an abstract class and so must instantiate objects at a more specialized level in the hierarchy. An abstract class defines a set of attributes and operations that some class must use (depends on) If an operation is not abstract, then its behaviour is defined in the abstract class, i.e. there is an implementation, but this may be overriden in a more specialized subclass.

22 2007ACS-3913 Ron McFadyen22 Abstract Classes Duck RubberDuck performfly() swim() display() The swim operation is overridden in RubberDuck. Both subclasses have implementations of display(). MallardDuck display() swim() display() The abstract class has its name in italics. The performFly() and swim() operations are defined, but display() is not defined (it is an abstract operation)


Download ppt "2007ACS-3913 Ron McFadyen1 Class Diagram See Schaum’s UML Outline, especially chapters 4, 5, 6, 7."

Similar presentations


Ads by Google