Unit 2 Notes - Ooad
Unit 2 Notes - Ooad
CLASS NAME
ATTRIBUTES
OPERATION OR
METHODS
Applying UML: Common Class Diagram
Notation
Relationship Notation
Generalization
Association
Aggregation
Composition
Dependency
Definition: Classifier
A UML classifier is “a model element that
describes behavioral and structure features”.
Classifiers can also be specialized.
In class diagrams, the two most common
classifiers are regular classes and interfaces.
Attribute Text and Association Lines
Attributes of a classifier (also called structural
properties in the UML) are shown several ways:
attribute text notation, such as currentSale : Sale.
association line notation
both together
The full format of the attribute text notation is:
visibility name : type multiplicity = default
{property-string}
Attribute Text and Association Lines
A navigability arrow pointing from the source
(Register) to target (Sale) object.
A multiplicity at the target end
A rolename (currentSale) only at the target end
Attribute Text and Association Lines
Data type
Boolean, Date (or DateTime), Number,
Character, String (Text), Time, Address, Color,
Geometrics (Point, Rectangle), Phone Number,
Social Security Number, Universal Product Code
(UPC), SKU, ZIP or postal codes, enumerated
types.
public class Register
{
private int id;
private Sale currentSale;
private Store location;
// ... }
The UML Notation for an Association
End
navigability arrow
rolename - to indicate the attribute name
multiplicity
property string
{ordered} or {unique}
{ordered, List}
{ordered} or {unique} - UML - defined keyword that
implies the elements of the collection are (the suspense
builds...) ordered.
{List} - the collection attribute lineItems
Operations and Methods
Third compartment in UML Class diagram is
operation or Methods
Syntax:
visibility name (parameter-list) : return-type
{property-string}
property string {name1=value1,
name2=value2} format,
such as {abstract, visibility=public}.
Dependency
The UML includes a general dependency
relationship that indicates that a client element
has knowledge of another supplier element and
that a change in the supplier could affect the
client.
Dependency is illustrated with a dashed arrow
line from the client to supplier.
when to show a dependency
There are many kinds of dependency
having an attribute of the supplier type
sending a message to a supplier
receiving a parameter of the supplier type
the supplier is a superclass or interface
when to show a dependency
In class diagrams use the dependency line to
global parameter variable
local variable
static-method (when a call is made to a static method
of another class)
Example of dependency
public class Sale {
public void updatePriceFor( ProductDescription
description ) {
Money basePrice = description.getPrice();
//...
}
// ...
}
Example of dependency
Domain Model Refinement
Generalization and specialization are fundamental
concepts in domain modeling.
Conceptual class hierarchies are often the basis of
inspiration for software class hierarchies.
Software class hierarchies
exploit inheritance
reduce duplication of code.
Generalization
Generalization is the activity of identifying
commonality among concepts and defining
superclass (general concept) and subclass
(specialized concept) relationships.
Notation
Example
The concepts CashPayment, CreditPayment,
and CheckPayment are all very similar.
Payment Payment
amount : Money
1 1
Product Contains Product
(b) itemID
Catalog Description
Person
2
*
parent child
Creates 4