UML Class Object Diagram I UML Class Diagram

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. my. Chair: Represented in the UML notation. : Bus Object name and no type : Truck : Plane Object name (id) and type : Ship PN 62001: 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 my. Chair: your. Chair: the. Brown. Sofa: 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 Person SSN name address drive() Run(). . . class name attributes (fields) operations (methods) person 1: Person SSN = 123. . . name= Jane address=Norway person 2: Person SSN = 122. . . name = James 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 patients. Journal; public Patient(String name, Doctor created. By) { super(name); patients. Journal = new Journal(); patients. Journal. set. Created. By(created. By); patients. Journal. set. Concerns(this); } public Journal get. Patients. Journal(){ return patients. Journal; } public void set. Patients. Journal(Journal patients. Journal) { this. patients. Journal = patients. Journal; } } 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: reality mapping owner model UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 9

Subclass and Superclass The class of human beings The subclass of ”female objects” People is superclass of Female Person 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 address Employee is a specialisation of Person inheritance or specialization subclass Employee SSN = 123. . . name = Jane address = Norway title = accountant department = accounting An object of type Employee title department UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 11

Multiple Inheritance • UML and OWL supports multiple inheritance. • Some object-oriented theoreticians claim that multiple inheritance should not be used! (e. g. , Java). Cassette Book volume : Integer Cassette. Book UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 12

One Common Ancestor for All Classes In Java all classes have a common ancestor called Object. In OWL it is called Thing. In C++ UML this is not the case. Object hash. Code Person Car Employee UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 13

Linking Objects are typically connected in some way or another. For example: Jane is married to James, Jane owns a car. Person married Jane: Person : married ownership Car Class Model association : ownership some. Wreck: Car Object Model (model instance of the class model) 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 Arm 2 1 Person 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: 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 gender : String Female Male Person Gender Female Person Undecided ? Androgyni 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] Introduction to Object-oriented Software Development, J. Pettersen Nytun page no. 19, 2/23/2021

Object Behaviour * can. Be. Use. By can. Use * operations / behaviour sending a message time lifeline for object office: Coffee. Machine 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, 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 described. By 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 The “specified. By role” is a specialization of the “described. By role. ” described. By given described. By specifies specified. By System In 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. The specification of a software system; the implementation (system) must conform to the model. A system is a group of interacting, interrelated, or interdependent elements that form a complex whole. Person name Model 1 * Car : Person name=“Bob” : Car A Model Instance snapshot UML Class Diagram & Object Diagram I, Jan Pettersen Nytun, page no. 23

Domain Model What is a Domain Model described. By 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/Domain. Modelling. pdf] Introduction to Object-oriented Software Development, J. Pettersen Nytun page no. 24, 2/23/2021

• A UML class diagram can be used to describe a domain model. • Some would say that a domain model is an Domain Model ontology. described. By given Domain • The model is a model of software which is the main purpose of UML. Model specified. By specifies System Introduction to Object-oriented Software Development, J. Pettersen Nytun page no. 25, 2/23/2021
- Slides: 25