Object-oriented modeling Class/Object Diagrams

22
Object-oriented modeling Class/Object Diagrams Karolina Muszyńska Based on: http://www.csun.edu/~dn58412/IS431/IS431_SP13.html S. Wrycza, B. Marcinkowski, K. Wyrzykowski „Język UML 2.0 w modelowaniu SI”

description

Object-oriented modeling Class/Object Diagrams. Karolina Muszyńska. Based on : http://www.csun.edu/~dn58412/IS431/IS431_SP13.html S. Wrycza, B. Marcinkowski, K. Wyrzykowski „Język UML 2.0 w modelowaniu SI”. Object Modeling – class/object diagrams. Static view - class/object diagrams - PowerPoint PPT Presentation

Transcript of Object-oriented modeling Class/Object Diagrams

Page 1: Object-oriented modeling Class/Object Diagrams

Object-oriented modeling

Class/Object Diagrams

Karolina Muszyńska

Based on: http://www.csun.edu/~dn58412/IS431/IS431_SP13.html S. Wrycza, B. Marcinkowski, K. Wyrzykowski „Język UML 2.0 w modelowaniu SI”

Page 2: Object-oriented modeling Class/Object Diagrams

Static view - class/object diagrams◦ role◦ basic concepts◦ advanced concepts◦ examples

2

Object Modeling – class/object diagrams

Page 3: Object-oriented modeling Class/Object Diagrams

Class diagrams – kind of UML diagrams showing the static view of the system, constituting the basis for the future object-oriented database. Class diagrams depict the system’s object structure and show object classes that the system is composed of as well as the relationships between classes.

Object diagrams - they are similar to class diagrams but instead of depicting object classes they model actual object instances, showing the structure of the systems in a given moment of time.

3

Class/object diagrams - role

Page 4: Object-oriented modeling Class/Object Diagrams

Conceptual diagram – class diagram including basic elements, using class, attributes and behavior names, which are clear and understandable for the user.

Implementation diagram – class diagram enriched by additional elements like data types, visibility, association classes, generalization relationships, or realizations.

4

Class diagrams - types

Page 5: Object-oriented modeling Class/Object Diagrams

Object – anything that is or is capable of being seen, touched, or otherwise sensed, and about which users store data and associate behavior (which is important in the considered domain)

Attributes - data that represents characteristics of interest about an object (everything what is known about an object is represented by the attributes)

Behavior/Methods - refers to things that the object can do and that correspond to functions that act on the object’s data (or its attributes)

Class - a set of objects sharing a common structure – attributes and behavior, and common relationships and meaning.

5

Class/object diagrams – basic concepts

Page 6: Object-oriented modeling Class/Object Diagrams

6

Class/object diagrams – basic concepts

Class

Class name

Methods with output data types

Attributes with data types

Page 7: Object-oriented modeling Class/Object Diagrams

7

Class/object diagrams – basic concepts

Object

Object name

Values of the attributes

Page 8: Object-oriented modeling Class/Object Diagrams

An object/class relationship is an association that exists between one or more objects/classes. It is defined by business rules and/or common practices. There are four types of relationships among classes: association, generalization, dependency and realization.

Association - main type of relationship describing the possible set of associations among objects of the associated classes.

Navigation is the defined direction of communication between classes; if not defined the default navigation is bi-directional.

Multiplicity defines how many instances of one class can be associated with one instance of another class.

8

Class/object diagrams – basic concepts

Page 9: Object-oriented modeling Class/Object Diagrams

9

UML Multiplicity NotationsMultiplicity Multiplicity

UML

Notation Association with Multiplicity

Association Meaning

Exactly 1

1

DepartmentEmployee 1Works for

DepartmentEmployee

An employee works for one and only one department.

Zero or one 0..1 0..1Has SpouseEmployeeAn employee has either one or no

spouse.

Zero or more

0..*or*

0..*Makes PaymentCustomer

PaymentCustomer Makes *

A customer can make no payment

up to many payments.

One or more 1..*

CourseUniversity Offers 1..*A university offers at least 1

course up to many courses.

Specific range

7..9

GameTeam 7..9Has A team has either 7, 8, or 9 games

scheduledscheduled

Page 10: Object-oriented modeling Class/Object Diagrams

10

Class/object diagrams – basic concepts

0..*Customer Orderplaces1

contractor contract

Association

RolesRoles

Association name

MultiplicityMultiplicity

Page 11: Object-oriented modeling Class/Object Diagrams

Aggregation – a special kind of relationship, which shows that some objects/classes are made up of other objects/classes. By identifying aggregation relationships we can partition a very complex object and assign behaviors and attributes to the individual objects within it. There are two types of aggregation relationships: ◦composition - all part-objects make up and

live in the whole-object,◦shared aggregation /aggregation/ - implies

that parts may be shared by many wholes.

11

Class/object diagrams – basic concepts

Page 12: Object-oriented modeling Class/Object Diagrams

12

Aggregation Relationship

Operation Team

Doctor Nurse Admin staff

“is a part of” relationships (part-objects may be shared by many whole-objects)

Page 13: Object-oriented modeling Class/Object Diagrams

13

Composition Relationship

Order

Order item

“is made of” relationships (all part-objects make up and live in the whole-object)

Book

Page

Page 14: Object-oriented modeling Class/Object Diagrams

Visibility – access modifier which determines the access level of the attributes or methods of the object class. Visibility defines whether attributes and methods of specific classes can be seen and used by other classes. UML specifies 4 main visibility levels:◦ „-” private – only objects within the same class can see and use the

attributes or methods,◦ „#” protected – only objects within the same class and from descendent

classes can see and use the attributes or methods,◦ „+” public – objects of any class can see and use the attributes or

methods,◦ „~” package - only classes within the same package can see and use

the attributes or methods. There is a rule that class attributes should be set private and the

external access to them is made possible by public methods.

14

Class/object diagrams – advanced concepts

Page 15: Object-oriented modeling Class/Object Diagrams

Multiple association – a situation when associated classes can play different roles to each other and so there are multiple associations between them. Each association should be named or characterized.

15

Participant Auction

is seller

is buyer

Class/object diagrams – advanced concepts

Page 16: Object-oriented modeling Class/Object Diagrams

Reflexive association – a situation when there is an association between different objects of the same class (an association binding the class with itself).

16

Automobile platform

transports

passenger car

1

1..10

Class/object diagrams – advanced concepts

Page 17: Object-oriented modeling Class/Object Diagrams

Generalization relationship - indicates that one of the two related classes - the subclass (child) is considered to be a specialized form of the other - the superclass (parent) and superclass is considered as ‘generalization' of subclass. In other words the child class is a specific type of the parent class and assumes all the characteristics of its parent class.

The generalization relationship is also known as the inheritance relationship.

The parent class can be either a real class or an abstract class. The abstract class has no real object instances, it is only a generalization of real objects which are specified as child classes.

17

Class/object diagrams – advanced concepts

Page 18: Object-oriented modeling Class/Object Diagrams

18

Generalization Relationship

- “is a kind of” relationships

Employee

Doctor Nurse Admin staff

Page 19: Object-oriented modeling Class/Object Diagrams

Realization relationship - denotes the implementation of the functionality defined in one class by another class (interface). Relationship in which one model element (the client) realizes (implements or executes) the behavior that the other model element (the supplier) specifies. A realization relationship between classes and interfaces shows that the class realizes the operations offered by the interface.

Realizations can only be shown on class or component diagrams.

19

Class/object diagrams – advanced concepts

Page 20: Object-oriented modeling Class/Object Diagrams

20

Class/object diagrams – advanced concepts

Interface

Realization relationship

Page 21: Object-oriented modeling Class/Object Diagrams

Find the potential objects (the best way is to review each use case to find nouns that correspond to business entities or events).

Select the proposed objects (clean the list of all potential business objects from: synonyms, nouns outside the scope of system, nouns that are roles without unique behavior or are external roles, unclear nouns that need focus and nouns that are really actions or attributes).

Identify attributes and operations of the classes. Identify associations and multiplicity (to help insure that all possible

relationships are identified we can create a class matrix). Identify generalization relationships (we should look for all one-to-one

multiplicity relationships between objects because they may be generalization relationships, as well as for classes that have common attributes and behaviors).

Identify aggregation relationships (we must remember that aggregation relationships do not imply inheritance but they propagate behavior).

The first step should be to identify related classes and build class diagrams for each particular use case and next build an integrated class diagram for the whole system.

21

Building a Class Diagram

Page 22: Object-oriented modeling Class/Object Diagrams

22

Class diagram – example