Top Banner
RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert
56

RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Dec 30, 2015

Download

Documents

Amanda French
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

RAJIKA TANDON

SOFTWARE DESIGN

CIS 453 - Software Specification & Design

Instructor: Dr. E. Sibert

Page 2: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

DESIGN The design of a system is essentially a blueprint or a plan for a solution for the system.

Here we consider a system to be a set of modules with clearly defined behavior which interact with each other in a defined manner to produce some behavior or services for its environment.

The design process for software systems often has two levels. At the first level the focus is on deciding which modules are needed for the system, the specifications of these modules, and how the modules should be interconnected.

This is what may be called the module design or the high-level design.

In the second level, the internal design of the modules, or how the specifications of the module can be satisfied, is decided. This design level is often called detailed design or logic design.

Detailed design essentially expands the system design to contain a more detailed description of the processing logic and data structures so that the design is sufficiently complete for coding.

Page 3: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object model?

An object model defines the structural relationships and dynamic interaction between a group of related objects.

An object diagram represents a specific collection of objects,

with specific attribute values and relationships.

Therefore it looks like a snapshot of an O-O system at some instant in time.

Page 4: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Outline

Object modeling Class vs instance diagrams Attributes Operations and methods Links and associations Examples of associations Two special associations

Aggregation Inheritance

Page 5: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Definition: Object Modeling Main goal: Find the important abstractions Steps during object modeling

1. Class identification Based on the fundamental assumption that we can find

abstractions 2. Find the attributes 3. Find the methods 4. Find the associations between classes

Order of steps Goal: get the desired abstractions Order of steps secondary, only a heuristic Iteration is important

What happens if we find the wrong abstractions? Iterate and correct the model

Page 6: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Class Identification

Identify the boundaries of the system Identify the important entities in the system Class identification is crucial to object-oriented modeling Basic assumption:

1. We can find the classes for a new software system (Forward Engineering)

2. We can identify the classes in an existing system (Reverse Engineering)

Page 7: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Pieces of an Object Model Classes Associations (Relations)

Part of- Hierarchy (Aggregation) Kind of-Hierarchy (Generalization)

Attributes Detection of attributes Application specific Attributes in one system can be classes in another system Turning attributes to classes

Methods Detection of methods Generic methods: General world knowledge, design patterns Domain Methods: Dynamic model, Functional model

Page 8: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object vs Class Object (instance): Exactly one thing A class describes a group of objects with similar properties Object diagram: A graphic notation for modeling objects, classes

and their relationships ("associations"): Class diagram: Template for describing many instances of

data. A class diagram describes object classes.

Object class: group of objects with similar properties (attributes), common behavior(operations), common relationships to other objects)

Useful for taxonomies, patters, schemata...

Instance diagram: A particular set of objects relating to each other. Useful for discussing scenarios, test cases and examples

Page 9: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Class and Instance Diagrams

Inspector

joe:Inspector

mary:Inspector

anonymous:Inspector

Class Diagram

Instance Diagram

Page 10: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Common uses of object diagrams are:

1. to illustrate the system state at a high level of abstraction, before and after some action (e.g. instruction execution)

i.e. dynamic modeling !!

2. to analyze the structure of recursive data types (classes) by unfolding a class diagram.

Page 11: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Attributes – A data value held by the objects in a class.

name:stringage: integer

Inspector

name = “Joe”age = 24

joe:Inspector

name = “Mary”age = 18

mary: Inspector

Page 12: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Operation, Signature or Method? What when?

( Feature –A generic word for either attribute /operation) Operation: A function or

transformation applied to objects in a class. All objects in a class share the same operations (Analysis Phase)

Signature: Number & types of arguments, type of result value. All methods of a class have the same signature (Object Design Phase)

Method: Implementation of an operation for a class (Implementation Phase)

Polymorphic operation: The same operation applies to many different classes.

Workorder

File_name: StringSize_in_bytes: integerLast_update: dateStickies: array[max]

print()delete()open()close()write()read()

Page 13: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Links and Associations Links and associations establish relationships among objects

and classes.

Link: A (physical/conceptual) connection between two object

instances. A link is like a tuple. A link is an instance of an association

Association: An association describes a set of links like a class describes

a set of objects. Basically a bidirectional mapping. One-to-one, many-to-one, one-to-many.

Page 14: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Notation for multiplicity:

1 one and only one exactly 1 0 zero or one 0 or 1

(optional) +1 one or more > = 1 M- N from M to N M to N greater than or equal to zero > = 0

(many)

Page 15: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

1-to-1 and 1-to-many Associations

Has-capital

One-to-one association

One-to-many association

City

name:String

Workorder

schedule()

StickyNote

x: Integery: Integerz: Integer

Country

name:String

Page 16: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object Instance Diagram Example for 1-to-many

:Sticky

x,y,z=(-1,0,5)

:WorkOrder :Sticky

x,y,z=(1,10,1)

:Sticky

x,y,z=(10,1,2)

Page 17: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Many-to-Many Associations

Work on Mechanics Plane

Page 18: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Ternary and n-ary relations are represented

using the diamond as before, e.g.

Object_1 :Class_1

Object_2 :Class_2

Object_3 :Class_3

Page 19: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

We can use object diagrams to understand

recursively defined classes. For example,

the class diagram

Binary_Tree

0 .. 2

0,1

Page 20: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

T1 : BinaryTree

T2 : BinaryTree

T3 : BinaryTree

T4 : BinaryTree

T5 : BinaryTree

Page 21: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.
Page 22: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Do associations have direction? A association between two classes is by default a bi-directional mapping.

If you want to make A a client, and B a server, you can make the association unidirectional. The arrowhead points to the server role:

Class A can access class B and class B can access class A Both classes play the agent role.

A B

A Baccesses

Name DirectionName of association

Association Direction

Class A ( the “client”) accesses class B (“the server”). B is also called navigable.

Page 23: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Relation R between classes X and Y is:

n-to-… if for every object y :Y there are

n distinct objects x1 ,…, xn : X with

xi R y for i = 1 ,…, n

…-to-m if for every object x :X there are

m distinct objects y1 ,…, ym : Y with

x R yi for i = 1 ,…, m

Page 24: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Roles A role name is the name that uniquely identifies one end of an

association. A role name is written next to the association line near the

class that plays the role. When do you use role names?

Necessary for associations between two objects of the same class

Also useful to distinguish between two associations between the same pair of classes

When do you not use role names? If there is only a single association between a pair of

distinct classes, the names of the classes serve as good role names

Page 25: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Example of Role

Problem Statement : A person assumes the role of repairer with respect to another person, who assumes the role of inspector with respect to the first person.

PersonCreates Workorders

inspector

repairpersonCreates Workorders

Person Person

Person

Page 26: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Qualification The qualifier improves the information about the multiplicity of

the association between the classes. It is used for reducing 1-to-many multiplicity to 1-1 multiplicity

With qualification: A directory has many files, each with a unique name

Without qualification: A directory has many files. A file belongs only to one directory.

Directory Filefilename

DirectoryFile

filename

1 *

0..11

Page 27: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Example

Problem Statement : A stock exchange lists many companies. However, a stock exchange lists only one company with a given ticker symbol. A company may be listed on many stock exchanges, possibly with different ticker symbols. Find company with ticker symbol AAPL.

StockExchangeCompany

tickerSym

lists

Page 28: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Use of Qualification reduces multiplicity

StockExchange CompanytickerSym 0..11

StockExchangeCompany

tickerSym

Directory FILEfilename

Page 29: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Company Personoffice

officer

Organization

Many-to-Many Qualification

Page 30: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation

Models "part of" hierarchy Useful for modeling the breakdown of a

product into its component parts (sometimes called bills of materials (BOM) by manufacturers)

Page 31: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation

Plain association: peer relationship.Aggregation: whole/part relationship. - An object may be a part of ONLY one aggregate at a time.

1

*

Company

Department

whole

part

Page 32: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation

Special kind of association For “part-whole” relationships For “has-a” relationships Aggregation-by-Value: Composition

Aggregation-by-Reference: Aggregation

Page 33: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Composition

In Composition (composite aggregation): - An object may be a part of ONLY one composite at a time. - Whole is responsible for the disposition of its parts.

Window

Frame*

1

whole

part

Page 34: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Composition (by Value)

gfdgfdgfdgfdgfdg

Page 35: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation (by Reference)

Product Catalog Product

Roll Call Student1 *

Page 36: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation vs. Composition

Both denote whole-part relationships

Both enable modeling at multiple levels of abstraction: whole or part

Page 37: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation vs Composition (contd.)

Aggregation: does not link the lifetimes of the whole and its parts. Aggregation can occur when a class is a collection or container of other classes, but where the contained classes do not have a strong life cycle dependency on the container—essentially, if the container is destroyed, its contents are not.

Composition: usually has a strong life cycle dependency between instances of the container class and instances of the contained class(es): If the container is destroyed, normally every instance that it contains is destroyed as well. Note that (where allowed):

Parts with non-fixed multiplicity can be created after the composite itself. lifetime

Such parts can be explicitly removed before the death of the composite. lifetime

An object may be a part of only one composite at a time. strong ownership

Page 38: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Generalization

Also called Inheritance or Specialization. Connects generalized classes to more specialized

classes. Sometimes called the “is-a” relationship because each

instance of a subclass is an instance of the superclass as well.

NOTATION :

A triangle connecting the superclass to its subclasses. The superclass connected by a line to the apex of the triangle. The subclasses are connected by lines to a horizontal bar attached to the base of the triangle.

Page 39: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation Vs GeneralizationBoth associations describe trees (hierarchies)

AGGREGATION: Aggregation relates instances (involves two or more different objects). Two distinct objects are involved; one of them is a part of the other. An aggregation tree is composed of object instances that are all part of a

composite object. “part-of” relationship.

GENERALIZATION: Generalization relates classes (a way to structure the description of a single

object). It is a way of structuring the description of a single object. An generalization tree is composed of classes that describe an object “a-kind-of”,”is-a” relationship.

Page 40: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Class relationshipsAggregation: • Represented by has-a relationship• Also called Whole-part, Composition, or Embedding• Cardinality is associated with this relationship

Inheritance• Represented by Is-A relation• No cardinality is associated• Also referred to as generalization/specialization

Association• It is used when objects of two classes communicate or there is a dependency that doesn’t fit the category of aggregation or inheritance• Cardinality is associated

Page 41: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Grouping constructs:Module:

A logical construct for grouping classes, associations, and generalizations. It captures one perspective or view of a situation.

For example:

Electrical, Plumbing and ventilation modules are different views of a building.

SHEET:

A mechanism for breaking a large object model into a series of pages.

Page 42: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

2. Associationsa structural relationship that describes a set of links, a link being a connection between objects.

Can be directed labels Can have multiplicity & role names

1. Dependencya semantic relationship between two things in which a change to one thing (independent) may affect the semantics of the other thing (dependent).

Revision - Relationships

Directed is optional and label is optional.

0..1employer

*

employee

Aggregation a special kind of association. It represents a structural relationship between the whole and its parts. Aggregation is inherently TRANSITIVE. An aggregate has parts, which may inturn have parts. Represented by

a diamond.

3. Generalizationa specialization/generalization relationship in which objects of the specialized element (the child) are more specific than the objects of the generalized element.

Page 43: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Aggregation Vs Association Aggregation relates instances. If two objects are tightly bound by a part-whole relationship, it is

aggregation.

Vs

Association: If two objects considered are independent, even though they may

often be linked

Company Division Department

Person

Works for

Page 44: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

How do you find classes?

Learn about problem domain: Observe your client Apply general world knowledge and intuition Take the flow of events and find participating objects in use

cases Apply design patterns Try to establish a taxonomy ( classification, derivatives ) Do a textual analysis of scenario or flow of events (Abbott

Textual Analysis, 1983) Nouns are good candidates for classes

Page 45: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Mapping parts of speech to object model components [Abbot 1983]

Part of speech Model component Example

Proper noun object Jim Smith

Improper noun class Toy, doll

Doing verb method Buy, recommend

being verb inheritance is-a (kind-of)

having verb aggregation has an

modal verb constraint must be

adjective attribute 3 years old

transitive verb method enter

intransitive verb method (event) depends on

Page 46: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Example: Scenario from Problem Statement

Jim Smith enters a store with the intention of buying a toy for his 3 year old child.

Help must be available within less than one minute. The store owner gives advice to the customer. The advice

depends on the age range of the child and the attributes of the toy.

Jim selects a dangerous toy which is unsuitable for the child. The store owner recommends a more yellow doll.

( Is is-a (kind-of) and has-a present in the above text ? )

Page 47: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object Modeling in Practice: Class Identification

Foo

Balance

CustomerId

Deposit()Withdraw()GetBalance()

Class Identification: Name of Class, Attributes and Methods

Page 48: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object Modeling in Practice: Encourage Brainstorming

Foo

Balance

CustomerId

Deposit()Withdraw()GetBalance() Account

Balance

CustomerId

Deposit()Withdraw()GetBalance()

Naming is important!

“Dada”

Balance

CustomerId

Deposit()Withdraw()GetBalance()

Page 49: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object Modeling in PracticeAccount

BalanceAccountId

Deposit()Withdraw()GetBalance()

Customer

NameCustomerId

Find New Objects

Iterate on Names, Attributes and Methods

Bank

Name

Page 50: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object Modeling in Practice: A Banking System

Account

BalanceAccountId

Deposit()Withdraw()GetBalance()

Customer

NameCustomerId

Bank

Name

Find New Objects

Iterate on Names, Attributes and Methods

Find Associations between Objects

Has

Label the associations

Determine the multiplicity of the associations

*

Page 51: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object Modeling in Practice: Categorize!( many accounts belong to 1 bank OR a bank holds many accounts – aggregation)

SavingsAccount

Withdraw()

CheckingAccount

Withdraw()

MortgageAccount

Withdraw()

Customer

Name

CustomerId

Account

BalanceAccountId

Deposit()Withdraw()GetBalance()

Bank

NameHas

**

Page 52: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Object Modeling in Practice: Heuristics

Explicitly schedule meetings for object identification Try to differentiate between entity, boundary and control

objects Find associations and their multiplicity

Unusual multiplicities usually lead to new objects or categories

Identify Aggregation Identify Inheritance: Look for a Taxonomy, Categorize Allow time for brainstorming , Iterate, iterate

Page 53: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Summary

In this lecture, we described:

Identification of objects and classes Refinement of objects with attributes and operations Generalization Associations Aggregation Composition Multiplicity

Page 54: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

A static class model for ABC distributing company

Create the class model using the following class relations and the business rules:•An Invoice is composed of one or more Entries

•An Invoice is created for exactly one Customer•An Invoice is created from one or more CustomerOrders•An Invoice is used to update the AccountsReceivable account•An Inventory is composed of zero or more StockItems•A PackingOrder is initiated from one or more Invoices•A PackingOrder is created from Inventory items•A PackingOrder is used to update the Inventory•A StockOrder is received from a Supplier•A StockOrder is used to update the Inventory•A StockOrder is used to update the AccountsPayable account

Page 55: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

CustomerOrder Invoice AccountsReceivable Account

Customer Entry PackingOrder

Supplier Inventory

StockOrder StockItem AccountsPayable

updatesCreated from

updates

updates

Received from

Class Diagram (a rough sketch for the above problem)

Page 56: RAJIKA TANDON SOFTWARE DESIGN CIS 453 - Software Specification & Design Instructor: Dr. E. Sibert.

Notes:

Please refer to Design_Principles.doc, for details on:

•Coupling•Cohesion

References:

Notes derived from Ms. Chandrakala .C.B., Dept. of Information & Communication Technology,Manipal Institute of Technology, Manipal University, India: