20
Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Embed Size (px)

Citation preview

Page 1: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Unified Modeling LanguageUser Guide

Section 2—Basic Structural Modeling

Chapter 4—Classes

Page 2: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 2

Overview• Classes

– Attributes– Operations– Responsibilities

• Modeling the vocabulary of a system.• Modeling the distribution of responsibilities.• Modeling non-software “things”.• Modeling primitive types.• Modeling quality abstractions.

Page 3: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 3

Classes

• Description of a set of objects that share the same attributes, operations, relationships, and semantics.

Windoworiginsize

open()close()

nameattributes

operations

Page 4: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 4

Names

• Distinguishing identity.

• Textual string.

• Simple name.

• Prefixed by package name to generate path name.

Customer

Account

TemperatureSensor

Circuit

Java::awt::RectangleSimple names

path name

Page 5: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 5

Name Rules

• Consists of letters, numbers, and certain punctuation marks.

• Short noun phrases drawn from vocabulary of the domain.

• First letter of every word capitalized.TemperatureSensor

BrokerageAccount

Page 6: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 6

Attributes

• Named property of a class.• Describes a range of values that an instance

of the property may hold.• Short noun representing property of its

enclosing class.• First letter of every word capitalized except

the first.birthDateuserAccount

Page 7: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 7

Attributes (cont’d)

attributesheight : Floatwidth : FloatisStudent : Boolean = false

originsize

You can further specify an attribute by stating its class and possibly a default initial value

Page 8: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 8

Operations• Abstraction of something that can be done to

an object.• Shared by every object of the same class.• May cause object to change state.• Short verb representing behavior of

representing class.• First letter of every word capitalized except the

first.addUser()isEmpty()

Page 9: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 9

Operations (cont’d)

operations reset()setAlarm( t : Temperature )value() : Temperatureadd()

move()

You can specify an operation by stating its signature, covering the name, type and default value of all parameters and a return type

Page 10: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 10

Organizing• Only a subset of attributes and operations are

typically relevant to any one view.• Elide a class; hide non-relevant information.• Use stereotypes to

categorize.• Use ellipsis to specify

additional attributes oroperations

<<constructor>>new()new( p : Policy )<<process>>process( o : Order )…<<query>>isSuspect( o : Order )

Page 11: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 11

Responsibilities

• Contract or obligation of a class.

• Carried out by attributes and operations.

• Techniques– CRC cards (Class-Responsibility-

Collaborator);Kent Beck and Ward Cunningham; ’89

– Use case based analysis.

Page 12: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 12

Responsibilities (cont’d)

• Free-form text; one phrase per responsibility.

Responsibilities-- determine the risk of a customer order-- handle customer-specific criteria for fraud

FraudAgent

responsibilities

Page 13: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 13

Modeling Techniques

• Vocabulary.

• Distribution of responsibilities.

• Non-software things.

• Primitive types.

Page 14: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 14

Modeling Vocabulary

• Things used to describe the problem or solution. Found through CRC cards and/or use case analysis.

• Identify responsibilities for each abstraction.

• Provide attributes and operations needed to carry out responsibilities.

Page 15: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 15

Modeling Distribution of Responsibilities

• Identify a set of classes that work together to carry out some behavior.

• Identify responsibilities for each class.• Split classes with too much responsibility.• Collapse classes with trivial responsibility.• No class should do too little or too much.

Page 16: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 16

Modeling Non-software Things

• Model the thing as a class.

• Use stereotypes to give a distinctive cue.

• Consider nodes to model hardware.

• Use a unique icon.

Page 17: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 17

Modeling Primitive Types

• Model as a type using a class notation.

• Use stereotypes as necessary.

• Use constraints to represent valid values.<<enumeration>>

Boolean

falsetrue

<<datatype>>Int

{ value range –2**31 to +2**31-1}

Page 18: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 18

Hints & Tips

• Well-structured class– Provides a crisp abstraction drawn from

vocabulary of problem or solution.– Embodies small, well-defined set of

responsibilities.– Provides clear separation of the abstractions

specification and implementation.– Understandable and simple.– Extensible and adaptable.

Page 19: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 19

Hints & Tips (cont’d)

• Drawing a UML class– Show only properties that are important in

a specific context.– Organize long lists of attributes and

operations by grouping.– Show related classes in the same

diagrams.

Page 20: Unified Modeling Language User Guide Section 2—Basic Structural Modeling Chapter 4—Classes

Sung Kim CS6359 Slide 20

Summary• Classes

– Name.– Attributes.– Operations.– Responsibilities.

• Modeling techniques.– Vocabulary.– Responsibilities.– Non-software things.– Primitive types.