UML Class & Object Diagram I UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 1
Object-oriented modelling involves classes which function as types that describes their instances which are called objects. UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 2
Object-oriented modelling includes description of: - object properties - links between objects - object behaviour UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 3
Objects Icons representing “real world objects” of different types. myChair: :Bus :Plane Represented in the Object name (id) and type Object name and no type UML notation. :Truck :Ship PN62001 :Car Anonymous object, only type is given UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 4
Classify Objects Some objects share the same type of qualities so we may formulate a general concept = define a class. This is a form of abstraction - some of the differences between the objects are “abstracted away” (ignored). Furniture myChair: yourChair: theBrownSofa: A class describes a set of objects that have the same type of attributes, behaviour and relationships. UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 5
Class and Objects UML Notation class objects class name Person SSN person1:Person person2:Person attributes name (fields) address SSN = 123... SSN = 122... drive() operations name= Jane name = James Run() (methods) address=Norway address = USA ... UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 6
How does one show Classes and Objects in a Java Program? Introduction to Object-oriented Software Development, Jan.Pettersen Nytun page no. 7
public class Patient extends Person { private Journal patientsJournal; public Patient(String name, Doctor createdBy) { super(name); patientsJournal = new Journal(); patientsJournal.setCreatedBy(createdBy); patientsJournal.setConcerns(this); } public Journal getPatientsJournal(){ return patientsJournal; } public void setPatientsJournal(Journal patientsJournal) { this. patientsJournal = patientsJournal; } } Introduction to Object-oriented Software Development, Jan Pettersen Nytun page no. 8
Making a Model • You are to solves some problem in a domain . • Simplify and find what is essential for your problem . • OO modelling: ”Objects from reality” are mapped ”directly” onto objects in your model . chair: Seated in Tom: car: owner reality model mapping UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 9
Subclass and Superclass The class of human beings Person The subclass of ”female objects” People is superclass of Female Female Male Jane: James: Person The classes represented in the UML notation. Female Male UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 10
Class Hierarchy ~ Reuse by Inheritance An employee is a special type of person, so if you already have a Person class and needs an Employee class, then inheritance allows you to reuse class Person. superclass Person Jane:Employee SSN name SSN = 123... address name = Jane Employee is a inheritance address = Norway specialisation or specialization title = accountant of Person department = accounting subclass Employee An object of type Employee title department UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 11
Multiple Person name Inheritance Employee Owner title • UML and OWL supports multiple inheritance. WorkingOwner • Some object-oriented Cassette Book theoreticians claim that volume : Integer volume : Integer multiple inheritance should not be used! (e.g., Java). CassetteBook UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 12
One Common Ancestor for All Object Classes hashCode In Java all classes have a common ancestor called Object . Person Car In OWL it is called Thing . In C++ UML this is not the case. Employee UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 13
Linking Objects Objects are typically connected in some way or another. For example: Jane is married to James , Jane owns a car . ownership Person Car Class Model association married Object Model :ownership Jane:Person someWreck:Car (model instance of the class model) :married links James:Person UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 14
Part-of Relation Some objects can be seen as compost of other objects. Head 1 1 1 Person 2 Arm 1 2 Leg UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 15
There Are Typically Many Ways to Classify Objects Jim may be classified as a person, a male person, an employee, a student and so on - the context decides. xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: xxx: the classes may overlap (or they may be disjoint) UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 16
How to model gender? UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 17
Different Models May be Possible! Person Gender Person Gender Person gender : String Female Male Female Male Gender Person ? Androgyni Female Male Undecided Person Gender Female Male Androgyni UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 18
“Not all people feel at home in the categories male or female. Professor of sexology Esben Esther Pirelli Benestad believes there are seven different genders.” [https://www.nrk.no/norge/visste-du-at-det-finnes-sju-kjonn_-1.13057760] 8/17/2016 Introduction to Object-oriented Software Development, J.Pettersen Nytun page no. 19,
Object Behaviour canUse * canBeUseBy * operations / behaviour Jane : Person office : CoffeeMachine sending a message pourCoffe( ) addOneLumpOfSugger( ) addOneLumpOfSugger( ) time addMilk( ) lifeline for object office:CoffeeMachine UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 20
An Object-Oriented Program ------ Objects Work Together and Solve Problems • Objects have identity. • Objects have state , the values of the attributes defines the state. The state change when the values of the attributes change. • Some objects are linked together . • The objects communicate by sending messages to each other (messages follows the links ) . Sending a message is the same as asking an object to perform one of its operations (methods). UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 21
Descriptive Models Model describedBy given System E.g. physics : - the system under study is nature (which is given) - the mission is to come up with a description (model) that is so good that it can be used to predict and explain natural phenomenon. UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 22
Specification (Prescriptive) & Descriptive Model Model Model The “ specifiedBy role” is a specialization of the specifiedBy describedBy “describedBy role.” specifies given describedBy specifiedBy System System In physics the system under study is nature (which The specification of a software system; is given); the mission is to come up with a description the implementation (system) must conform (model) that is so good that it can be used to predict to the model. and explain natural phenomenon. A system is a group of interacting, interrelated, or interdependent elements that form a complex whole. :Person :Car Person Car * 1 name name=“Bob” :Car Model A Model Instance snapshot UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 23
Domain Model describedBy What is a Domain Model given Domain “A domain model is a model of the domain within which an Enterprise conducts its business. The Domain Model for one Enterprise should be the same as that for any other Enterprise conducting business in the same do main. When we get down to more detailed levels, different people have different ideas about what constitutes a Domain Model.” [http://www.aptprocess.com/whitepapers/DomainModelling.pdf] 8/17/2016 Introduction to Object-oriented Software Development, J.Pettersen Nytun page no. 24,
• A UML class diagram can be used to describe a domain model. • Some would say that a domain model is an ontology. Domain Model describedBy given Domain • The model is a model of software which is the main purpose of UML. Model specifiedBy specifies System 8/17/2016 Introduction to Object-oriented Software Development, J.Pettersen Nytun page no. 25,
Recommend
More recommend