Presentation is loading. Please wait.

Presentation is loading. Please wait.

UML Class & Object Diagram I

Similar presentations


Presentation on theme: "UML Class & Object Diagram I"— Presentation transcript:

1 UML Class & Object Diagram I

2 Object-oriented modelling involves classes which function as types that describes their instances which are called objects. - You look around, and you see one particular chair, a table, a person, and you realize that the objects are related - the person is sitting on the chair by the table. - A system developed by using the object-oriented technique can be seen as a system consisting of a number of objects which cooperate to solve a task.

3 Object-oriented modelling includes description of: object properties links between objects object behaviour - You look around, and you see one particular chair, a table, a person, and you realize that the objects are related - the person is sitting on the chair by the table. - A system developed by using the object-oriented technique can be seen as a system consisting of a number of objects which cooperate to solve a task.

4 Objects Icons representing “real world objects” of different types.
myChair: :Bus :Plane :Truck :Ship PN62001:Car Represented in the UML notation. Anonymous object, only type is given Object name and no type Object name (id) and type At this moment you have x number of busses, one of them is represented by the buss picture.

5 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 person has a name, the same number of chromosomes, ... ) A class describes a set of objects that have the same type of attributes, behaviour and relationships.

6 Class and Objects UML Notation
Person SSN name address drive() Run() ... class attributes (fields) operations (methods) class name person1:Person SSN = name= Jane address=Norway person2:Person SSN = name = James address = USA objects You when you declare the class you select which attributes and operations (behavior) are of interest for your system. Objects of the given class will have individual values for the specified attributes.

7 How does one show Classes and Objects in a Java Program?

8 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;

9 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: car: Tom: Seated in owner model mapping reality

10 Subclass and Superclass
The class of human beings The subclass of ”female objects” People is superclass of Female Jane: James: Person Female Male The classes represented in the UML notation. Person Female Male

11 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. Person SSN name address Employee title department An object of type Employee Jane:Employee SSN = name = Jane address = Norway title = accountant department = accounting inheritance or specialization Employee is a specialisation of Person superclass subclass An object of type Employee is also a Person. An will have all attributes that a Person has plus all of its own.

12 Multiple Inheritance UML and OWL supports multiple inheritance.
Some object-oriented theoreticians claim that multiple inheritance should not be used! (e.g., Java). Cassette volume : Integer Book CassetteBook Some times when we describe a new class we see that this new class should have characteristics from two (or more) existing classes. It is then possible to inherit from both classes.

13 One Common Ancestor for All Classes
Object hashCode In Java all classes have a common ancestor called Object. In OWL it is called Thing. In C++ UML this is not the case. Person Car E.g., common operations: clone(), getClass() Employee

14 Linking Objects Class Model
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 married association Object Model (model instance of the class model) :ownership Jane:Person someWreck:Car Draw associations… :married links James:Person

15 Part-of Relation Some objects can be seen as compost of other objects.
Head 1 1 Arm 1 Person 2 1 2 Leg

16 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. the classes may overlap (or they may be disjoint) xxx: Big box could be Person small once could be Male and Employee…

17 How to model gender?

18 Different Models May be Possible!
Person Gender Person gender : String Gender Person Female Male Female Male Gender Person ? Androgyni Female Male Undecided Big box could be Person small once could be Male and Employee… Gender Person Female Male Androgyni

19 “Not all people feel at home in the categories male or female
“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.” [ 1/14/2019

20 Object Behaviour time operations / behaviour sending a message
canUse * canBeUseBy * operations / behaviour time sending a message Synchronous and also asynchronous “message passing”… lifeline for object office:CoffeeMachine

21 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).

22 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.

23 Specification (Prescriptive) & Descriptive Model
The “specifiedBy role” is a specialization of the “describedBy role.” Model describedBy specifiedBy given describedBy specifiedBy specifies System 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 Car :Person :Car 1 * name name=“Bob” :Car Model A Model Instance snapshot

24 Domain Model What is a Domain Model “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.” [ describedBy given Domain 1/14/2019

25 A UML class diagram can be used to describe a domain model.
Some would say that a domain model is an ontology. The model is a model of software which is the main purpose of UML. Domain Model describedBy given Domain Model specifiedBy specifies System 1/14/2019


Download ppt "UML Class & Object Diagram I"

Similar presentations


Ads by Google