cs3773 software engineering lecture 04 uml class diagram

28
CS3773 Software Engineering Lecture 04 UML Class Diagram

Upload: colin-young

Post on 03-Jan-2016

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS3773 Software Engineering Lecture 04 UML Class Diagram

CS3773 Software Engineering

Lecture 04UML Class Diagram

Page 2: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37732

Objects are discrete entities with well defined boundaries and encapsulate

– States– Behaviors

Classes represent types of objects that share a set of features: attributes, operations, and relations

Classes describe key concepts involved in the problem domain

Classes are basic building blocks of OO system

Class and Object

Page 3: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37733

Elements of class diagram:– Class represented as a box containing three

compartments Name Attributes Operations

– Relation represented as a line between two classes Association Generalization Aggregation and composition

UML Class Diagram Syntax

Page 4: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37734

UML class diagrams can be used in three distinct ways depending on the phase of system development:

– Conceptual (Domain Models) Requirements phase

The diagram represents the problem that the software should solve

Classes are real-world concepts in the system's environment

Not necessarily a direct mapping to how these will be implemented (although they may end up being classes in the software system)

Class Diagram: Perspectives

Page 5: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37735

– Design The diagram is complete: both attributes and operations

The diagram depicts only the interfaces of software classes, but still avoids implementation details (information hiding)

– Implementation The diagram depicts interfaces and implementations of classes

Class Diagram: Perspectives

Page 6: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37736

Class

Classes are entities from the problem domain– Actors that interact with system

– Any information that the system stores, analyzes, transforms, displays, etc.

– Transient objects

e.g., business transactions, phone conversations, etc.

Classes are named, usually, by short singular nouns

Syntax: A box with three compartments for names, attributes, and operations respectively

Page 7: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37737

Class Diagram – An Example

Class Diagram – An Example

Page 8: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37738

Identifying Class

Classes are usually derived from the use cases for the scenarios currently under development

Brainstorm about all the entities that are relevant to the system

Noun Phrases– Go through the use cases and find all the noun phrases

– Watch out for ambiguities and redundant concepts

Page 9: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS37739

Attribute

Attributes are simple data associated with a class

e.g., integer, sets, dates

Attributes are properties of a class

Attributes are information that distinguishes one instance of the class from another instance

They are distinguishing characteristics of the objects

Syntax: name: type = default value

Page 10: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377310

Operation

Operations are the responsibilities/services of an object in the class

Operations query or transform values of object's attributes, change state

A class's attributes and operations document the purpose of the class --- what information it maintains, and how that information can be manipulated

Syntax: name (parameters) : return-type

Page 11: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377311

Static Attribute and Operation

Static attributes model data values shared by all objects of the class

e.g., number of objects

Static operations are class-related operations not offered by instances of the class

e.g., “create ()”, “search ()”

Syntax: underlined attribute or operation

Page 12: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377312

Association

An association is a relationship between classes

An association is a name, usually short verb – Some people name every association

– Others name associations only when such names will improve understanding

e.g., avoid names like “is related to”, and “has”

An association represents different types of relationships

e.g., data flow, requests, parts of compound class

Page 13: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377313

Association Syntax

An association may have– An association name

– Multiplicity

– Role names

– Qualifier

– Association class

– Navigability

Page 14: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377314

Multiplicity

Multiplicities on associations give lower and upper bound on the number of instances of the local class that can be linked to one instance of the remote class

Syntax: 1, *, etc. at the association end. Examples:– * (zero or more)

– 1 .. * (one or more)

– 1 .. 40 (one to 40)

– 5 (exactly 5)

– If no multiplicity is specified, the default is 1

Page 15: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377315

Multiplicity

Multiplicities on classes indicate how many instances of the class can be at run time

Multiplicities constrain the number of objects

Syntax: 1, *, etc. at the top right corner of class

Page 16: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377316

Role Name

Is a part of association

Describes how the object at the association end is viewed by the associated object

Is useful for specifying the context of the class

Syntax: name at the association end

Page 17: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377317

Qualified Association

Qualified association is an association key that identifies the object at the other end of the association

Qualifier is a key or index used to identify one or fewer objects from set of many objects

Qualifier is often an attribute of the class at the other end of the association, and the attribute is recognized as uniquely identifying one or fewer objects of the class.

Syntax: name in box at the end of an association

Page 18: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377318

Association Class

Association class allows to add attributes, operations to an association

The association contains more information

Syntax: class connected to the association by a dashed line

Constraint: only one instance of association class between any two associated objects

Page 19: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377319

Generalization

Indicates an “is-a” relationship

All instances of the subclass are instances of the super class

A subclass inherits all attributes, operations and associations of the parent

The common attributes and operations are placed in the superclass; subclasses extend the attributes, operations, and associations as they need them

Syntax: open triangle at the superclass end of the association

Page 20: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377320

Aggregation

Indicates a loose “has-a” relationship

The compound class is made up of its component classes

Represents the “whole-part” relationship, in which one object consists of the associated objects

– The whole controls the relationship

– The part services requests from the whole

Syntax: hollow diamond at the compound class end of the association

Page 21: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377321

Aggregation Semantics

Whole can exist independently of the parts

Part can exist independently of the whole

Whole is incomplete if some of the parts are missing

It is possible to have shared ownership of the parts by several wholes

Page 22: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377322

Composition

Composition is a particular kind of aggregation

Component classes are physically part of the compound class

e.g., a car is composed of an engine, wheels, etc.

The component class dies if the compound class dies

Syntax: filled diamond at the compound class end of the association

Page 23: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377323

Composition Semantics

Component belong to exactly one compound at a time

Compound is responsible for the creation and destruction of all its components

Compound may also release its components to other compounds

If the compound is destroyed, it must either destroy all its components, or give responsibility for them over to some other classes

Page 24: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377324

Review of Class Diagram

Class is a set of discrete entities that share the same features

Class encapsulates data (attributes) and functions (operations: queries of modifiers)

Multiplicity constrains the number of objects participating in a relationship at any point in time

Relationship represents connections between classes – Association: role name, qualifier, association class,

navigability

– Generalization

– Aggregation and composition

Page 25: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377325

UML Object Diagram

Object is an instance of some class

Object diagram is a snapshot of the objects in a system

Object diagram represents all the instances of classes (objects) and their associations (links) at a point of time

Object diagram gives better feeling of problem by showing examples

Page 26: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377326

UML Object Diagram Syntax

Object is a box with two compartments: object name and attributes

Objects name is underlined– Class name alone

– Object name alone

– Object name concatenated with the class name, separated by a colon

– Name convention: starting with a lowercase letter

Relations among objects are represented as links

Page 27: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377327

UML Object Diagram – An Example

Ann: Patron

Jo: Patron

Tom: Patron

A: Book

: Book1

: Book2

: Book

Page 28: CS3773 Software Engineering Lecture 04 UML Class Diagram

UTSA CS377328

Reading Assignments

UML 2 and The Unified Process – Chapter 7, “Objects and classes”– Chapter 8, “Finding analysis classes” – Chapter 9, “Relationships”– Chapter 18, “Refining analysis relationships”