You are on page 1of 46

SS ZG514 Object Oriented Analysis and Design

BITS Pilani
Pilani Campus

BITS Pilani
Pilani Campus

Lecture Session-8
22- 08-13
2

BITS Pilani
Pilani Campus

Design Class Diagrams

Design Class Diagrams


Objectives Create design class diagrams (DCDs). Identify the classes, methods, and associations in a DCD. Aggregation and composition Roles Navigability Qualified association Derived association Constraints Association classes

BITS Pilani, Pilani Campus

Design Class Diagrams (DCD)


The UML has notation for showing design details in static structure: Class Diagrams. The definition of design class diagrams occurs within the design phase. The UML does not specifically define design class diagram. The creation of design class diagrams is dependent upon the prior creation of: Interaction diagrams identifies the SW classes that participate in the solution, plus the methods of classes. Conceptual model adds detail to the class definitions.
BITS Pilani, Pilani Campus

UML Class
A class is a template for actual, in-memory, instances

Produt serialNumber name price buy() display()

Class Name Attributes

Operations

BITS Pilani, Pilani Campus

UML Class

BITS Pilani, Pilani Campus

Class Attributes
Attributes are the instance and class data members
Class data members (underlined) are shared between all instances (objects) of a given class Data types shown after ":" Attribute compartment

Visibility shown as + public private # protected

visibility name : type

BITS Pilani, Pilani Campus

Class Operations
Operations are the class methods with their argument and return types

Public (+) operations define the class interface

Class methods (underlined) have only access to class data members, no need for a class instance (object)
visibility name : type Operations compartment

BITS Pilani, Pilani Campus

Visibility
public (+) external objects can access the member private (-) only internal methods can access the member protected (#) only internal methods, or methods of specialized objects can access the member

BITS Pilani, Pilani Campus

Association
Represent relationship between instances of classes Student enrolls in a course Courses have students Courses have exams Etc. Association has two ends Role names (e.g. enrolls) Multiplicity (e.g. One course can have many students) Navigability (unidirectional, bidirectional)

BITS Pilani, Pilani Campus

Structural Modeling: Core Relationships


Construct
association

Description

Syntax

a relationship between two or more classifiers that involves connections among their instances. A special form of association that aggregation specifies a whole-part relationship between the aggregate (whole) and the component part. generalization a taxonomic relationship between a more general and a more specific element. a relationship between two modeling dependency elements, in which a change to one modeling element (the independent element) will affect the other modeling element (the dependent element).
BITS Pilani, Pilani Campus

Multiplicity (Cardinality)
These symbols indicate the number of instances of one class linked to one instance of the other class.

26-Oct-13

BITS Pilani, Pilani Campus

13

Aggregation
Container Class Class C AGGREGATION

Aggregation:

Class E1

Class E2

expresses a relationship among instances of related classes. It is a specific kind of Container-Containee relationship. express a more informal relationship than composition expresses.

Computer

Aggregation is appropriate when Container and Containees have no special access privileges to each other.

Motherboard

BITS Pilani, Pilani Campus

Composition
Association
Whole Class Class W

Models the partwhole relationship

Composition
Class P1 Class P2

Part Classes Example

Also models the partwhole relationship but, in addition, Every part may belong to only one whole, and If the whole is deleted, so are the parts
Example:
A number of different chess boards: Each square belongs to only one board. If a chess board is thrown away, all 64 squares on that board go as well.

BITS Pilani, Pilani Campus

Aggregation Association
We can model objects that contain other objects by way of special associations called aggregations and compositions. An aggregation specifies a whole-part relationship between an aggregate (a whole) and a constituent part, where the part can exist independently from the aggregate. Aggregations are denoted by a hollow-diamond adornment on the association. Engine

Car
Wheel

BITS Pilani, Pilani Campus

Composition Association
A composition indicates a strong ownership and coincident lifetime of parts by the whole (i.e., they live and die as a whole). Compositions are denoted by a filled-diamond adornment on the association. Scrollbar
Titlebar Menu

Window

1 .. *

BITS Pilani, Pilani Campus

Generalization
Generalization is another name for inheritance or an "is-a" relationship.

BITS Pilani, Pilani Campus

18

Generalization Relationship
UML permits a class to inherit from multiple superclasses, although some programming languages (e.g., Java) do not permit multiple inheritance. Student Employee

TeachingAssistant

BITS Pilani, Pilani Campus

Dependency
A dependency exists between two elements if changes to the definition of one element may cause changes to the other The dependency relationship is useful to depict nonattribute visibility between classes. Parameters Global or local visibility A dashed directed line Many dependencies have already special UML notations superclass interface implementation attributes as associations.
BITS Pilani, Pilani Campus

Dependency
A dependency indicates a semantic relationship between two or more elements. Indicating one element has knowledge of another element

Circle Point
Move(p:Point)

21 BITS Pilani, Pilani Campus

Dependency Relationship
Change in specification of one class can change the other class. This can happen when one class is using another class. The dependency from CourseSchedule to Course exists because Course is used in both the add and remove operations of CourseSchedule. CourseSchedule Course add(c : Course) remove(c : Course)

BITS Pilani, Pilani Campus

Association Relationship
Associations can also be objects themselves, called link classes or an association classes. Registration modelNumber serialNumber warrentyCode

Product

Warranty

BITS Pilani, Pilani Campus

Association Class
which is both an association and a class is an association class

24 BITS Pilani, Pilani Campus

Qualified Associations
A qualified association associates two objects using a qualifier to select objects at the other end of the association. A qualifier is an attribute or set of attributes which has a unique value for each object in the class.

BITS Pilani, Pilani Campus

Qualified composition
In fact we can combine the qualified association notation with the other adornments on associations For example, we can add back the information that this particular association is a composition

BITS Pilani, Pilani Campus

Constraints
A constraint is a condition that has to be satisfied by any correct implementation of a design The formal constrains can be written in OCL, the Object Constraint Language (developed by IBM) OCL is intended to be
Formal, so that constraints written in it are unambiguous Easy to use, so that every developer can write constraints in it

BITS Pilani, Pilani Campus

Interface Services
Interfaces do not get instantiated. <<interface>> ControlPanel
getChoices : Choice[] makeChoice (c : Choice) getSelection : Selection No attributes or state. Rather, they specify the services offered by a related class. Same notation as class except: has word interface All methods are public

BITS Pilani, Pilani Campus

Realization- Interface
A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol). Interface is a set of operation the class carries out It is rendered by a dashed line with a hollow triangle towards the specified.
Keyboard
brandName numOfKeys ctl() pageDown() <<interface>> TypeWriter Keyboard

OR
keyStroke()

brandName numOfKeys
ctl() pageDown() TypeWriter

29 BITS Pilani, Pilani Campus

Association - Self
A Company has Employees. A single manager is responsible for up to 10 workers.
1 Employee
Responsible for
manager

0..10
worker

30 BITS Pilani, Pilani Campus

Relationships

26-Oct-13

BITS Pilani, Pilani Campus

31

Singleton Classes

32 BITS Pilani, Pilani Campus

Steps to make a DCD.


Identify all the classes participating in the SW solution by analyzing the interaction diagrams. Draw them in a class diagram. Duplicate the attributes from the associated concepts in the conceptual model. Add method names by analyzing the interaction diagrams. Add type information to the attributes and methods. Add the associations necessary to support the required attribute visibility. Add navigability arrows to the associations to indicate the direction of attribute visibility. Add dependency relationship lines to indicate nonattribute visibility.
BITS Pilani, Pilani Campus

Developing a Domain Class Diagram:


the NextGen POS DCD
1) Identify software classes: Register ProductCatalog Store Payment

Sale ProductSpecification SalesLineItem

2) Begin drawing a class diagram

3) Include the attributes from the domain model

BITS Pilani, Pilani Campus

Class Attributes Visualisation

Attributes can be shown visually for class associations, or in text : for basic data types only

BITS Pilani, Pilani Campus

Collection Attributes

prefer the visual version rather than the text version


BITS Pilani, Pilani Campus

Operations and Methods


Operations syntax in UML
visibility name (parameter-list) : return-type {property-string}

Visibility marks include + (public) and (private). Operations are usually assumed public if no visibility is shown. A UML method is the implementation of an operation, it may be illustrated using: An interaction diagram A class diagram
BITS Pilani, Pilani Campus

Add method names


: Register : Sale makePayment(cashTendered) makePayment(cashTendered)

messages in interaction diagrams indicate operations in the class diagrams

Register ... makePayment() ... 1 currentSale ...

Sale

classes identified in the interaction diagrams are declared in the class diagrams

makePayment() ...

from interaction diagrams model class & interaction diagrams in parallel


BITS Pilani, Pilani Campus

Domain Model to Design Model


The domain model included conceptual class diagram, vision, use cases etc., the design model includes design class diagrams, interaction and package diagrams (etc.). From analysis to design the move is from a conceptual view to a software view of the problem

39 BITS Pilani, Pilani Campus

Parameters

BITS Pilani, Pilani Campus

Method body pseudo-code also optional

Register method // pseudo-code or a specific language is OK public void enterItem( id, qty ) { ProductDescription desc = catalog.getProductDescription(id); sale.makeLineItem(desc, qty); } ... endSale() enterItem(id, qty) makeNewSale() makePayment(cashTendered)

BITS Pilani, Pilani Campus

Add associations and navigability


implicitly contain? What attribute does ProductCatalog

BITS Pilani, Pilani Campus

Dependency
A dependency exists between two elements if changes to the definition of one element may cause changes to the other The dependency relationship is useful to depict nonattribute visibility between classes. Parameters Global or local visibility A dashed directed line Many dependencies have already special UML notations superclass interface implementation attributes as associations.
BITS Pilani, Pilani Campus

What does dependency add to this DCD?


the Sale has parameter visibility to a ProductDescription, and thus some kind of dependency ProductDescription ... Sale ... updatePriceFor( ProductDescription ) ... 1..* lineItems ... ... SalesLineItem ...

BITS Pilani, Pilani Campus

Class Diagram
1 ProductCatalog 1 Contains 1..* StockItem barcode description ItemSold Contained-in brand Described-by qtySold paidPrice : Currency 1..* 1 retailPrice : Currency 1 qtyInStock sell() buy() 1 Sale checkOutNo date&Time Captured-on 1 1 1 POST Used-by 1 Houses 1..* Belongs-to 1 Store

calculateCost() Records-sales-on printDocket() 1 1 1 addItem() cancelItem() Cashier Initiated-by (from Use Case View) 1

Payment amountDue

Paid-by

accept() cancel()

CashPayment amountReceived changeGiven calcChange()

CreditPayment

EFTPOSPayment cashOut

BITS Pilani, Pilani Campus

Conclusions
Class diagrams Attributes and operations of classes Association Composition Dependency Aggregation Generalization

46 BITS Pilani, Pilani Campus

You might also like