OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
OO Techniques & UML Class DiagramsSE3A04 – Tutorial
Jason Jaskolka
Department of Computing and SoftwareFaculty of EngineeringMcMaster University
Hamilton, Ontario, [email protected]
October 17, 2011
Jason Jaskolka OO Techniques & UML Class Diagrams 1 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Outline
1 Review of Object-Orientation
2 UML Notation for Class Diagrams
3 Examples
4 Questions
Jason Jaskolka OO Techniques & UML Class Diagrams 2 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Object-Orientation
Definition (Class)
A class is a construct that is used as a blueprint to create instancesof itself. Classes usually contain a list of attributes (state variables)and a list of methods.
Definition (Object)
An object is an instance of a class. Objects of the same class sharethe same set of attributes, yet will typically differ in what thoseattributes contain.
Definition (Method)
A method is a procedure or function associated with a class whichenable a class object’s behaviour.
Jason Jaskolka OO Techniques & UML Class Diagrams 3 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
UML
Definition (UML)
The Unified Modelling Language (UML) is a means of preciselyexpressing requirements, analysis models and designs, in a platformindependent manner.
UML is the result of a successful unification of the manyobject-oriented analysis and design notations which aroseduring the 1980’s and 1990’sVersion 1.1 was endorsed by the Object Management Group(OMG), representing many companies and organizations, as astandard for object-oriented analysis and designA major revision of UML, to version 2.0, was published in 2004As of March 2011, UML is in version 2.4 beta
Jason Jaskolka OO Techniques & UML Class Diagrams 4 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Class Diagrams
Definition (Class Diagram)
Class diagrams are the backbone of almost every object orientedmethod, including UML. They describe the static structure of asystem.
Purpose is to depict the classes within a modelClasses have attributes, operations and relationships withother classes
All can be graphically depicted using UML class diagrams
Jason Jaskolka OO Techniques & UML Class Diagrams 5 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Class Diagrams
Jason Jaskolka OO Techniques & UML Class Diagrams 6 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Class
Classes represent an abstraction of entities with commoncharacteristicsIllustrate classes with rectangles divided into compartmentsPlace the name of the class in the first partition (centred,bolded, and capitalized)List the attributes in the second partitionWrite operations into the third partition
Jason Jaskolka OO Techniques & UML Class Diagrams 7 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Active Class
Active classes initiate and control the flow of activity, whilepassive classes store data and serve other classesIllustrate active classes with a thicker border
Jason Jaskolka OO Techniques & UML Class Diagrams 8 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Visibility
Use visibility markers to signify who can access theinformation contained within a classPrivate visibility hides information from anything outside theclass partitionPublic visibility allows all other classes to view the markedinformationProtected visibility allows child classes to access informationthey inherited from a parent class
Jason Jaskolka OO Techniques & UML Class Diagrams 9 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Associations
Associations represent static relationships between classesPlace association names above, on, or below the associationlineUse a filled arrow to indicate the direction of the relationshipPlace roles near the end of an associationRoles represent the way the two classes see each otherNote: It is uncommon to name both the association and theclass roles
Jason Jaskolka OO Techniques & UML Class Diagrams 10 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Multiplicity
Place multiplicity notations near the ends of an associationThese symbols indicate the number of instances of one classlinked to one instance of the other classFor example, one company will have one or more employees,but each employee works for one company only
Jason Jaskolka OO Techniques & UML Class Diagrams 11 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Constraints
Place constraints inside curly braces {}
Jason Jaskolka OO Techniques & UML Class Diagrams 12 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Aggregation and Composition
Aggregation is a relationship in which the “whole” class playsa more important role than the “part” class, but the twoclasses are not dependent on each otherUse a hollow diamond to represent a simple aggregationrelationshipComposition is a special type of aggregation that denotes astrong ownership between Class A, the whole, and Class B, itspartIllustrate composition with a filled diamondThe diamond end in both a composition and aggregationrelationship points toward the “whole” class or the aggregate
Jason Jaskolka OO Techniques & UML Class Diagrams 13 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Aggregation and Composition
Jason Jaskolka OO Techniques & UML Class Diagrams 14 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Generalization
Generalization is another name for inheritance or an “is a”relationshipIt refers to a relationship between two classes where one classis a specialized version of anotherUse a hollow arrow head to denote a generalizationrelationshipFor example, a Circle and a Square are both shapes; so theclass Circle and Square would have a generalizationrelationship with the class Shape
Jason Jaskolka OO Techniques & UML Class Diagrams 15 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Generalization
Jason Jaskolka OO Techniques & UML Class Diagrams 16 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Allocation of Student Rooms
Example (Allocation of Student Rooms)
Draw a class diagram to represent the following system:Over the summer holiday, university students can book collegehall accommodation online. They must specify their name,student number, course, year, and identify three collegeresidences as their preferences.The system makes an allocation of students to rooms beforethe start of the term, trying, where possible, to allocatestudents to a room in one of their preferred halls.
Jason Jaskolka OO Techniques & UML Class Diagrams 17 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Allocation of Student Rooms
Jason Jaskolka OO Techniques & UML Class Diagrams 18 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Vehicles
Example (Vehicles)
Draw a class diagram to represent an imaginary application thatmust model different kinds of vehicles such as bicycles, motor bikesand cars.
Jason Jaskolka OO Techniques & UML Class Diagrams 19 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Vehicles
Jason Jaskolka OO Techniques & UML Class Diagrams 20 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
University Courses
Example (University Courses)
Draw a class diagram for an imaginary application that modelsuniversity courses.
Jason Jaskolka OO Techniques & UML Class Diagrams 21 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
University Courses
Jason Jaskolka OO Techniques & UML Class Diagrams 22 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Company Payroll
Example (Company Payroll)
Draw a class diagram that models an imaginary company payrollsystem.
Jason Jaskolka OO Techniques & UML Class Diagrams 23 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Company Payroll
Jason Jaskolka OO Techniques & UML Class Diagrams 24 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Scrabble
Example (Scrabble)
Draw a class diagram for a Scrabble system.
Jason Jaskolka OO Techniques & UML Class Diagrams 25 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Scrabble
Jason Jaskolka OO Techniques & UML Class Diagrams 26 / 27
OutlineReview of Object-Orientation
UML Notation for Class DiagramsExamplesQuestions
Questions
Questions?
Jason Jaskolka OO Techniques & UML Class Diagrams 27 / 27