Title: 3' Analysis
13. Analysis
- Overview of OO concepts
- Classes and objects
- Finding classes
- Class Diagram
23.2 Classes and Objects
- Classes
- Associations
- (Static Modelling)
3Classes and Objects
- 1 Classes Objects
- 2 The Class Diagram
- 3 Associations
- 4 Aggregation Composition
- 5 Generalisation
4 Classes and Objects
- Classes, Objects and their relationships are the
primary way to model. - A class is like a type and therefore an object
is like a variable.
5 An Object has ...
- Attributes (data).
- Behaviour (operations).
- State (memory)
- Identity
- Responsibilities
6 An example Object ...
- A sensor
- Attributes (data) Value, Rate of change
- Behaviour (operations) acquire, report ...
- State (memory) Last value, Last Rate
- Identity Robot arm joint sensor
- Responsibilities Gives co-ordinates for arm
7 The Class Sensor
- All sensors share certain characteristics hence
we have a class of sensors. - But each individual example is an object.
- (An instance of the class)
8Attributes
- Describe the state and characteristics of the
object. - Must be typed, primitives like integer, real,
Boolean, point, area, enumeration. May be
language specific. - Visibility may be public (), private (-) or
protected ().
9Attributes (Contd.)
- Class variables have scope across every instance
of class, change one changes all. - Property strings may be used to define allowable
properties of an attribute. Used for enumeration
types. - Syntax
- visibility name type-expression initial-value
property-string - Only name and type are mandatory.
10Example Class
Name, bold
Public, typed
Sensor
Linear_Value Real Rate_Of_Change Real
0.0 Sensor_Name String Sensor_Location
String - Controller String Unspecified -
number_of_sensors Integer status Status
ONON, OFF
Default value
Private, typed, default value
Class variable
Property
11Operations
- Operations manipulate attributes and perform
other tasks. - Scope is the Class.
- Operation signature is composed of name,
parameters and return type. - name(parameter-list) return-type-expression
- Scope and visibility rules apply.
12Syntactic Constructs
- Formal syntax is as follows
- visibility name(parameter-list)
return-type-expression property-string - parameter-list specified as
- name type-expressiondefault-value
- All operations must have unique signature.
- Default values on parameters are Ok.
13On the Class Diagram
Figure
Signatures ? Class scope ? Defaults ?
-size Size -pos Position figCounter Integer
draw() resize(percentX Integer25,
percentY30) returnPos() Position incCounter()
Integer
percentX10, percentY10 percentX27,
percentY30 percentX25, percentY30
MyFigure.resize(10,10) MyFigure.resize(27) MyFigur
e.resize()
14Cardinality Examples
Employee
Dept
1..
NameString NumberEmpNo
NameName
Rent
0..1
Member
Video
Has
Customer
Account
AccNoAccount
Balance Real
15Class Object Representation
0..1
Rent
Member
Video
Night for day Video
John Doe Member
Sunset Boulevard Video
16Navigable Associations
- Used to indicate responsibility, later may be
translated into pointer mechanism. - May be bi-directional.
owns
0..
Person
Car
17Recursion
- Self referential construct.
- Complex construct, may not be supported by target
language.
owner
User
container
Directory
0..1
authorised user
contents
18Qualified Associations
- A qualified association relates two Object
Classes and a qualifier. - One-to-many and many-to-many associations may be
qualified. - The qualifier distinguishes among the set of
objects at the many end of an association.
19Qualified Associations
Directory
File
Is more clearly expressed as .....
Directory
File
File name
20Or-Association
- A constraint on two or more associations.
- Objects of a class may participate in at most one
of the associations at a time.
0..
Insurance Contract
1
0..
Insurance Co
or
1..
1..
Person
Company
21Ordered Association
- Shows implicit order of associations.
- Default is unordered.
ordered
Screen
Window
Visible on
ordered
Sensor
Controller
polls
22Association Class
- Class may be attached to association, and not
another class.
employer
Company
Person
0..1
Employment
Association Class
Period dateRange
23Shared Aggregation
- One person may be a member of many teams.
- Person is part of team, shared by N teams.
Person
Team
Members
24Composition Aggregation
- More restrictive. Strong ownership here.
- Rules
- Parts live inside whole, parts die with whole,
like automatic variables. - Multiplicity on whole side must be 0..1, on
part side may be anything. - Composition aggregation forms a tree of parts,
shared forms a network of parts.
25Three Composition Notations
Text
Listbox
Window
Button
menu
26Window
- Component not bold.
- May use syntax
- rollnameclassname
- Multiplicity shown.
Text
Listbox
Button
menu
27 Generalisation
- Generalisation and Inheritance allow sharing of
similarities among Classes while also preserving
differences. - Inheritance refers to mechanism of sharing
attributes operations between subclasses and
their superclass. - Default values of attributes methods for
operations may be overridden in subclass.
28Example
General
Financial service
Specific
Pension
Mortgage
Personal Loan
Insurance
29Subclass Concretises
FormControl
Display()abstract
ButtonElement
InputElement
Display()
Display()
30Implementation Issue
FormControl
- When Client invokes Display(), method is bound at
runtime. - Like pure virtual function in C.
Display()
Display()abstract
Client
ButtonElement
InputElement
Display()
Display()
31Constrained Generalization
- Generalisations may be
- Overlapping inherit multiple subclasses with
common superclass. - Disjoint opposite to overlapping.
- Complete all subclasses specified, no more
allowed. - Incomplete more subclasses may be added to
hierarchy.
32Engineering Process for Allocation of
Responsibility
- Process will lay down rules for timing of
allocation of responsibilities to classes from
use cases. - May use domain analysis, find classes
relationships, then allocate from use cases. - May find classes from use cases.
33Domain Analysis
Natural Language
Problem Domain
34Class Description
- Develop a Class description, either in textual
prose or some other structured form. E.G. using a
customer in a Bank - Customer a holder of one or more accounts in a
Bank. A customer can consist of one or more
persons or companies. A customer can make
withdrawals deposit money transfer money
between their accounts or to another account
query their accounts.
35Structured Class Description
Class Name Customer Description Personal or
company details Superclass User Name
Name Description Customers name Type String
(max. 12 chars) Cardinality 1 Name
Owns Description Details of bank accounts Type
Account Cardinality Many
36Structured Class Description (cont..)
Public Methods Name Pay_bill Parameters
amount, date, destination,
account. Description Customer may pay bills
through the Bank.
37 Class Diagram
1..
1..
1
1
owns
handles
Customer
Portfolio
Trader
0..
contains
0..
Instrument
Bond
Stock
Stock Option
38Class Diagram Notation
- Depicts static structure of classes.
- Classes represent things in the system.
- Classes may be related in many ways
- Associated
- Dependant
- Specialised
- Packaged
39 Object Diagram
Author
Computer
uses
Class Diagram
NameString ageinteger
NameString memoryinteger
0..1
1..
Object Diagram
LaptopComputer
BrianAuthor
NameDellLT memory32
DesktopComputer
Namebstone age38
NameDellMMX memory32