Introduction to Unified Modelling Language (UML) (part 2 Class diagram, Associations)

54
Introduction to Unified Modelling Language (UML) (part 2 Class diagram, Associations) 1

description

Introduction to Unified Modelling Language (UML) (part 2 Class diagram, Associations). Objects. What are Objects “ a discrete entity with a well-defined boundary that encapsulates state and behaviour ; an instance of a class” UML Reference Manual, 2nd Edition-2004 Observations - PowerPoint PPT Presentation

Transcript of Introduction to Unified Modelling Language (UML) (part 2 Class diagram, Associations)

Page 1: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Introduction toUnified Modelling Language (UML)(part 2 Class diagram, Associations)

1

Page 2: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Objects• What are Objects

• “a discrete entity with a well-defined boundary that encapsulates state and behaviour;

• an instance of a class” UML Reference Manual, 2nd Edition-2004• Observations

• an instance of a class• state is maintained in fields• behaviour is implemented via methods• every object is uniquely identified

2

Page 3: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

UML Object Notation

3

Page 4: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Classes• What are Classes

• “the descriptor for a set of objects that share the same attributes, operations, methods, relationships, and behaviour” UML Reference Manual, 2nd Edition-2004

• template for objects with similar features

4

Page 5: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

UML Class Notation

5

Page 6: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

UML Class Notation

6

Page 7: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

How Much to Show?• Scenarios

• scenario 1: inter-class relationship• scenario 2: behaviour of a class or classes• scenario 3: entity classes representing data entities

7

Page 8: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

How Much to Show?• Scenarios

• scenario 1: inter-class relationship• class boxes are probably enough with name compartment only

• scenario 2: behaviour of a class or classes• class boxes with name & operations compartment

8

Page 9: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Analysis Classes• What is an Analysis Class?

• represents an important concept of the problem domain• maps on to real-world concepts• an attempt to capture the big picture

9

Page 10: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Analysis Classes

10

Page 11: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Analysis Classes• Observations

• name reflects the intent of abstraction• focus clearly defined/understood• small & well defined set of responsibilities• high cohesion & low coupling

11

Page 12: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Classes• The three class types in the Unified Process are

• Entity classes• Boundary classes• Control classes

• UML notation

12

Page 13: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Entity Classes• An entity class models information that is long lived• Examples:

• Account Class in a banking information system• Mortgage Class and Investment Class in the information system

• Instances of all these classes remain in the information system for years

13

Page 14: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Boundary Classes• A boundary class models the interaction between the

information system and its actors• Boundary classes are generally associated with input and

output• Examples:

• Sales Report Class in the E-Commerce information system• Mortgage Listing Class and Investment Listing Class in the

information system

14

Page 15: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Control ClassesA control class models complex computations and

algorithms

Examples: • Compute GPA Student Class, in the PSU information system

15

Page 16: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Stereotypes

• UML notation for these three types of classes

• These are stereotypes (extensions of UML) • UML allows us to define additional constructs that are not part of UML

but which we need in order to model a system accurately

16

Page 17: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

The Unified Process and Classes

• The Unified Process does not describe how classes are extracted• Users of the Unified Process are expected to have a

background in object-oriented analysis and design• We temporarily suspend this discussion of the Unified Process to explain how classes are extracted, and then return to the Unified Process

17

Page 18: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Extracting Entity Classes• Entity class extraction consists of three steps that are carried out iteratively and incrementally:• Functional modeling

• Present scenarios of all the use cases (a scenario is an instance of a use case)

• Class modeling• Determine the entity classes and their attributes• Determine the interrelationships and interactions between the entity

classes• Present this information in the form of a class diagram

• Dynamic modeling• Determine the operations performed by or to each entity class• Present this information in the form of a statechart

18

Page 19: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Flowchart for Extracting Entity Classes

19

Page 20: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Initial Class Diagram: Painting System Case Study

• The second step in extracting the entity classes is class modeling• The aim of this step is to extract the entity classes,

determine their interrelationships, and find their attributes

• Usually, the best way to begin this step is to use the two-stage noun extraction method• Stage 1: Describe the information system in a single paragraph• Stage 2: Identify the nouns in this paragraph, then select the entity

classes from those nouns

20

Page 21: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Noun Extraction: Painting System Case Study

• Stage 1: Describe the information system in one paragraph:• Reports are to be generated in order to improve the effectiveness of

the decision-making process for buying works of art. The reports contain buying and selling information about paintings, which are classified as masterpieces, masterworks, and other paintings

21

Page 22: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Noun Extraction: Painting System (contd)• Stage 2: Identify the nouns in this paragraph

• Reports are to be generated in order to improve the effectiveness of the decision-making process for buying works of art. The reports contain buying and selling information about paintings, which are classified as masterpieces, masterworks, and other paintings

• The nouns are report, effectiveness, process, buying, work of art, selling, information, painting, masterpiece, and masterwork

22

Page 23: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Noun Extraction: Painting System (contd)• effectiveness, process and information are abstract nouns and are

therefore unlikely to be entity classes• Abstract nouns identify things that have no physical existence

• Nouns buying and selling are derived from the verbs “buy” and “sell”• They will probably be operations of some class

23

Page 24: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Noun Extraction: Painting System (contd)• Noun report is unlikely to be an entity class, because a

report is not long lived• A report is much more likely to be a boundary class

• Noun work of art is just a synonym for painting

24

Page 25: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

First Iteration of the Initial Class Diagram• This leaves four candidate entity classes:

• Painting Class, Masterpiece Class, Masterwork Class, and Other Painting Class

25

Page 26: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Second Iteration of the Initial Class Diagram• Consider the interrelationships between the entity classes• A masterpiece is a specific type of painting, and so is a

masterwork and an “other painting” • Painting Class is therefore the base class• Masterpiece Class, Masterwork Class, and Other Painting

Class are subclasses of that base class

26

Page 27: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Second Iteration of Initial Class Diagram (contd)

27

Page 28: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Third Iteration of the Initial Class Diagram• The class diagram does not reflect aspects of the pricing

algorithm

• When dealing with a masterwork• “The information system first computes the maximum purchase

price as if it were a masterpiece by the same artist”

28

Page 29: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Third Iteration of the Initial Class Diagram (contd)• That is, a masterwork has to have all the attributes of a

masterpiece (so that its maximum purchase price can be computed as if it were a masterpiece) and, in addition, it may have attributes of its own• This is modeled in the next slide

29

Page 30: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Third Iteration of the Initial Class Diagram (contd)

30

Page 31: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Fourth Iteration of the Initial Class Diagram• Another aspect of the pricing algorithm that is not

reflected in the current class diagram is• “The information system computes the coefficient of similarity

between each painting for which there is an auction record and the painting under consideration for purchase”

31

Page 32: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Fourth Iteration of the Initial Class Diagram (contd)

• Auctioned Painting Class is needed to make these comparisons• An auctioned painting must be a subclass of Painting Class• But a painting previously been sold at an auction somewhere in the

world has nothing to do with paintings currently on display for sale in Osbert’s gallery

32

Page 33: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Fourth Iteration of the Initial Class Diagram (contd)

33

Page 34: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Fourth Iteration of the Initial Class Diagram (contd)

• An instance of Painting Class is either • A painting that Osbert has bought (an instance of Gallery Painting

Class), or • A painting sold at some auction (an instance of Auctioned

Painting Class)

34

Page 35: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Initial Class Diagram: Painting System Case Study

• Why was the first iteration of the class diagram so inadequate? • The Painting System case study appears to be a straightforward data-

processing application• The one-paragraph description correctly did not incorporate the pricing

algorithm• Unfortunately, the algorithmic details turned out to be critical to

the class diagram

35

Page 36: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Initial Class Diagram: Painting System (contd)• The first iteration of the class diagram was no good

• However, repeated iteration and incrementation led to a reasonable class diagram

• This demonstrates the power of the iterative and incremental approach

36

Page 37: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Initial Class Diagram (contd)• Finally, we add the attributes of each class to the class

diagram• the result is shown on the next slide

• The empty rectangle at the bottom of each box will later be filled with the operations of that class

37

Page 38: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Fifth Iteration of the Initial Class Diagram (contd)

38

Page 39: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Fifth Iteration of the Initial Class Diagram (contd)

39

Page 40: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

• Done with the Painting System case study • Still the dynamic modeling – later

40

Page 41: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Design Classes• What is a Design Class?

• Integrates the problem domain & solution domain• problem domain → refined analysis classes• solution domain → implementation specific classes

• are complete, ready to be implemented

41

Page 42: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Design Classes• Concerns

• responsibility• the public methods imply a contract• code evolution should be considered

• inheritance• major concern of design classes (why?)

42

Page 43: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Inheritance• Concerns

• the strongest form of coupling between classes• “fragile base class” problem

• changes in the base class impact subclasses• inflexible to change

• fixed at runtime

43

Page 44: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Example: Ambitious John

44

Page 45: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Inheritance or Interface• Inheritance

• interface & implementation• concerns with reuse

• Interface• interface only• concerns with functionality contract• “design by contract”• concerns with reuse (what?)

45

Page 46: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Further Considerations• Student Self-Study

• Templates• Nested classes• Multiple Inheritance

46

Page 47: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

• What is an Association?• connection between two things (usually classes)• “for a link between two object, there must be an association

between the class of those objects”• link is an instance of an association• link can be represented by dependency relationship

47

Page 48: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Example

48

Page 49: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Reflexive Association

49

Page 50: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Reflexive Association

50

Page 51: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Aggregation

51

Page 52: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Composition

52

Page 53: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Association Classes

53

Page 54: Introduction to Unified  Modelling  Language (UML) (part 2 Class diagram, Associations)

Association Classes• Observations

• association classes are purely analysis classes• convert association class into normal design class

• use the various relationships to clarify• association (aggregation, composition, dependency)

• additional constraints to refine the model• navigation, multiplicity

54