21) Functional and Modular Design Prof. Dr. U. Amann 1. Functional - - PowerPoint PPT Presentation

21 functional and modular design
SMART_READER_LITE
LIVE PREVIEW

21) Functional and Modular Design Prof. Dr. U. Amann 1. Functional - - PowerPoint PPT Presentation

Fakultt Informatik, Institut fr Software- und Multimediatechnik, Lehrstuhl fr Softwaretechnologie 21) Functional and Modular Design Prof. Dr. U. Amann 1. Functional Design Technische Universitt Dresden 2. Modular Design


slide-1
SLIDE 1

Fakultät Informatik, Institut für Software- und Multimediatechnik, Lehrstuhl für Softwaretechnologie

21) Functional and Modular Design

Ø

  • Prof. Dr. U. Aßmann

Ø

Technische Universität Dresden

Ø

Institut für Software- und Multimediatechnik

Ø

http://st.inf.tu-dresden.de

Ø

Version 13-0.1 20.12.2010

  • 1. Functional Design
  • 2. Modular Design (Change-

Oriented Design)

  • 3. Use-Case Based Design
slide-2
SLIDE 2

Obligatory Readings

Ø Ghezzi Chapter 3, Chapter 4, esp. 4.2 Ø Pfleeger Chapter 5, esp. 5.7 Ø David Garlan and Mary Shaw. An Introduction to Software

  • Architecture. In: Advances in Software Engineering and Knowledge

Engineering, Volume I, edited by V.Ambriola and G.Tortora, World Scientific Publishing Company, New Jersey, 1993. Ø Also appears as CMU Software Engineering Institute Technical Report

CMU/SEI-94-TR-21, ESC-TR-94-21.

Ø http://www-2.cs.cmu.edu/afs/cs/project/able/ftp/intro_softarch/

intro_softarch.pdf

  • Prof. U. Aßmann

Modular Design 2

slide-3
SLIDE 3

Literature

Ø [Parnas] David Parnas. On the Criteria To Be Used in Decomposing

Systems into Modules. Communications of the ACM Dec. 1972 (15) 12.

Ø [Shaw/Garlan] Software Architecture. 1996. Prentice-Hall.

  • Prof. U. Aßmann

Modular Design 3

slide-4
SLIDE 4

21.1 FUNCTIONAL DESIGN

  • Prof. U. Aßmann

Modular Design 4

slide-5
SLIDE 5

Function-Oriented Methods

Ø Examples:

Ø Stepwise function refinement resulting in function trees Ø Modular decomposition with information hiding (Change-oriented

modularization, Parnas)

Ø Meyers Design-by-contract: Contracts are specified for functions with

pre- and postconditions

Ø (see OCL lecture) Ø Dijkstra’s and Bauer’s axiomatic refinement (not discussed here)

  • Prof. U. Aßmann

Modular Design 5

Which functionality will the system have? What are the subfunctions of a function?

slide-6
SLIDE 6

A Start for a Function Tree

Ø How to design the control software for a tea automaton?

  • Prof. U. Aßmann

Modular Design

produce tea

Produce Tea

6

slide-7
SLIDE 7

First Refinement of a Function Tree

  • Prof. U. Aßmann

Modular Design

put tea in pot add boiling water wait composition produce tea

Produce Tea .. is composed of .. Put tea in pot Add boiling water Wait

7

slide-8
SLIDE 8

Second Refinement of a Function Tree

  • Prof. U. Aßmann

Modular Design

put tea in pot add boiling water wait

fetch tea from tea box

  • pen

pot close pot produce tea

Produce Tea Put tea in pot Fetch tea from tea box Open pot Close pot Add boiling water Wait

8

slide-9
SLIDE 9

Produce Tea Put tea in pot Fetch tea from tea box Open pot Close pot Add boiling water Boil water Open pot Pour water in Close pot Wait

Third Refinement of a Function Tree

  • Prof. U. Aßmann

Modular Design

put tea in pot add boiling water

wait

fetch tea from tea box

  • pen

pot close pot produce tea boil water

  • pen

pot close pot pour water in pot

9

slide-10
SLIDE 10

Function Trees

Ø Function trees can also be derived by a 1:1 mapping from a

functional requirements tree (see ZOPP requirements lecture)

Ø Usually, for a system several function trees are develop, starting

with top-level functions in the context model

Ø Stepwise Refinement works usually top-down (Hierarchic

decomposition)

Ø Bottom-up strategy (composition) possible Ø Middle-out strategy blends composition and decomposition Ø Development of the “subfunction-of” (“call”) relationship: a part-of

relationship for functions: the function has which parts (subfunctions)?

Ø Usually implemented by call relationship (call graph)

Ø Syntactic stepwise refinement is indifferent about the semantics

  • f the refined model

Ø Semantic stepwise refinement proves that the semantics of the

program or model is unchanced

Ø Systems developed by semantic refinement are correct by construction

Ø Functions are actions, if they work on visible state

Ø In functional design, state is disregarded Ø State is important in action-oriented design, actions are usually related to

state transitions!

  • Prof. U. Aßmann

Modular Design 10

slide-11
SLIDE 11

Function Polyhierarchies

Ø If subfunctions are shared, polyhierarchies result with several roots and shared subtrees

  • Prof. U. Aßmann

Modular Design 11

put tea in pot add boiling water

wait

fetch tea from tea box

  • pen

pot close pot produce tea boil water

  • pen

pot close pot pour water in pot put coffee in pot fetch Coffee from tea box produce coffee

slide-12
SLIDE 12

Other Trees with Other Part-Of Relationships

Ø Many concepts can be stepwise refined and decomposed. Hierarchic decomposition is one of the most important development methods in Software Enineering: Ø Problem trees Ø Goal trees Ø Acceptance test trees Ø Requirements trees

  • Function trees
  • Feature trees (function trees describing grouping, variability and

extensibility)

Ø Attack trees Ø Fault trees Ø …. Ø The development is always by divide and conquer. Ø Think about: Which part-of relationships do they develop?

  • Prof. U. Aßmann

Modular Design 12

slide-13
SLIDE 13

21.1.2 MODULAR COMPOSITION: GROUPING MODULES AND COHESION

  • Prof. U. Aßmann

Modular Design 13

slide-14
SLIDE 14

Grouping Functions to Modules to Support Cohesion

Ø Group functions according to cohesion: “which function belongs to

which other function?”

Ø Minimize coupling of modules Ø Maximize coherence: encapsulate dependencies within a module

  • Prof. U. Aßmann

Modular Design

Module Tea Automaton { Produce Tea Add boiling water Wait } Module Tea Box { Fetch tea from tea box }

14

Module Water Boiler { Boil water } Module Pot { Open pot Put tea in pot Pour water in pot Close pot }

slide-15
SLIDE 15

Grouping Functions to Modules or Classes in UML

Ø Functions can often be grouped to objects (object-oriented encapsulation) Ø Then, they can be actions working on the state of the object (begin

  • f object-orientation)
  • Prof. U. Aßmann

Modular Design 15

<<module>> TeaAutomaton produceTea() addBoilingWater() wait() <<module>> WaterBoiler TeaBox fetchTea() Pot

  • pen()

putIn(Tea) pourIn(Water) close() boilWater()

slide-16
SLIDE 16

Heuristics and Best Practices

Ø Don't group too many items onto one abstraction level or into one

module (slim interface principle)

Ø Technical modules or classes (classes that do not stem from domain

modeling) can be found in similar ways, by grouping cohesive functions together

Ø Identify material modules or classes with CRUD interfaces (see

TeaBox and Pot):

Ø Create Ø Read Ø Update Ø Delete

Ø Identify tool modules or classes with “active functions”:

  • List<Material>
  • Edit<Material>
  • Navigate<Material>

Ø Identify command modules or classes (Design Pattern Command)

  • Tools are specific commands, working on materials
  • Prof. U. Aßmann

Modular Design 16

slide-17
SLIDE 17

Result: Call-Based Architectural Style

Ø Functional design leads to call-based architectural style with

statically known callees (static call graph)

  • Prof. U. Aßmann

Modular Design

Module Module Module System

call return call return call return call return cal l return

17

slide-18
SLIDE 18

Grouping Other Trees with other Part-Of Relationships

Ø Any hierarchic relationship can be grouped to modules based on cohesion Ø Problem trees è problem modules Ø Goal trees è goal modules Ø Acceptance test trees è acceptance test modules Ø Feature trees (describing variability, extensibility) è Feature modules Ø Attack trees è attack modules Ø Fault trees è fault modules Ø ….

  • Prof. U. Aßmann

Modular Design 18

slide-19
SLIDE 19

Why is Function-Oriented Design Important?

Ø Implementation of function trees in a functional language

Ø ... or a modular imperative language, e.g., Modula, C, or Ada-83.

Ø In some application areas, object-oriented design and languages

have severe disadvantages

Ø Employment in safety-critical systems:

Ø Proofs about the behavior of a system are only possible if the architecture

and the call graph are static. Then they can be used for proofs

Ø Due to polymorphism, object-oriented systems have dynamic architectures

(don't program your AKW with Java!)

Ø In embedded and real-time systems:

Ø Object-oriented language implementations usually are slower than those of

modular languages

Ø ... and eat up more memory

Ø In high-speed systems:

Ø Operating systems, database systems, compilers, ...

  • Prof. U. Aßmann

Modular Design 19

slide-20
SLIDE 20

21.2 CHANGE-ORIENTED MODULARIZATION WITH INFORMATION HIDING (VARIABILITY)

(Rep. from ST-1, left out here)

  • Prof. U. Aßmann

Modular Design 20

slide-21
SLIDE 21

What is a Module?

Ø Software should, according to the divide-and-conquer principle,

also physically be divided into basic parts, modules Ø A module groups a set of functions or actions Ø A module can be developed independently Ø errors can be traced down to modules Ø modules can be tested before assembling Ø A module can be exchanged independently Ø A module can be reused

Ø The terms module and component mean pretty much the same

Ø Often, a module is a programming-language supported component Ø Here: a module is a simple component Ø In the past, different component models have been developed Ø A component model defines features of components, their

compositionality, and how large systems are built with them (architecture)

Ø In course “Component-based SE”, we will learn about many different

component models

  • Prof. U. Aßmann

Modular Design 21

slide-22
SLIDE 22

How To Modularize a System?

Ø Parnas principle of change-oriented modularization (information

hiding) [Parnas, CACM 1972]:

Ø 1) Fix all design decisions that are likely to change Ø 2) Attach each of those decisions to a new module

Ø The design decision becomes the secret of a module (called module secret)

Ø 3) Design module interface that does not change if module secret

changes

  • Prof. U. Aßmann

Modular Design 22

slide-23
SLIDE 23

Information Hiding

Ø Information hiding relies on module secrets Ø Possible module secrets:

Ø How the algorithm works, in contrast to what it delivers Ø Data formats Ø Representation of data structures, states Ø User interfaces (e.g., AWT) Ø Texts (language e.g., gettext library) Ø Ordering of processing (e.g., design patterns Strategy, Visitor) Ø Location of computation in a distributed system Ø Implementation language of a module Ø Persistence of the data

  • Prof. U. Aßmann

Modular Design 23

slide-24
SLIDE 24

Module Interfaces

Ø Should never change!

Ø Well, at least be stable

Ø Should consist only of functions

Ø State should be invisible behind interfaces Ø Direct access to data is efficient, but cannot easily be exchanged Ø e.g., emply set/get methods for accessing fields of objects

Ø Should specify what is

Ø Provided (exported) Ø Required (imported)

  • Prof. U. Aßmann

Modular Design 24

slide-25
SLIDE 25

Different Kinds of Modules

Ø Functional modules (without state)

Ø sin, cos, BCD arithmetic, gnu mp,...

Ø Data encapsulators

Ø Hide data and state by functions (symbol table in a compiler) Ø Monitors in the parallel case

Ø Abstract Data Types

Ø Data is manipulated lists, trees, stacks, .. Ø New objects of the data type can be created dynamically

Ø Singletons

Ø Modules with a singular instance of a data structure

Ø Data-flow processes (stream processors, filters)

Ø Eating and feeding pipelines

Ø Objects

Ø Modules that can be instantiated

  • Prof. U. Aßmann

Modular Design 25

slide-26
SLIDE 26

What Have We Learned?

Ø When designing with functions, use function trees and subfunction

decomposition

Ø When grouping to modules, fix module secrets Ø The more module secrets, the better the exchange and the

reuseability Ø Change-oriented design means to encapsulate module secrets

Ø Functional and modular design are still very important in areas with

hard requirements (safety, speed, low memory)

  • Prof. U. Aßmann

Modular Design 26

slide-27
SLIDE 27

Conclusion of Information-Hiding Based Design

  • Prof. U. Aßmann

Modular Design

We have seen how important it is to focus on describing secrets rather than interfaces or roles of modules. When we have forgotten that, we have ended up with modules without clear responsibilities and eventually had to revise our design. [Parnas/Clements, The Modular Structure of Complex Systems, CACM]

27

slide-28
SLIDE 28

21.3 FUNCTION- ORIENTED DESIGN WITH USE-CASE DIAGRAMS

(repetition from ST-1)

  • Prof. U. Aßmann

Modular Design 28

slide-29
SLIDE 29

Use Case Diagrams

Ø Use Case Diagram (UCD) can be used in functional design

Ø A Use Case Diagram consists of several use cases of a system Ø A use case describes an application, a coarse-grain function or action of a

system, in a certain relation with actors

Ø A use case contains a scenario sketch

Ø Pseudocode text which describes the functionality

Ø Use Case diagrams can be used in Function-Oriented, Action-Oriented, or in

Object-Oriented Design

Ø From UCD, a function tree can be derived

  • Prof. U. Aßmann

Action Oriented Design

slide-30
SLIDE 30

30

Example Service Station

Ø A Service Station has 4 tasks [Pfleeger]

Ø Parking Ø Refueling Ø Maintenance Ø Preventive Maintainance

  • Prof. U. Aßmann

Action Oriented Design

Parking Refueling Maintenance Preventive Maintenance Customer Manager <<extends>>

slide-31
SLIDE 31

31

Questions for Use Cases

Ø What is the system/subsystem? Ø Who is Actor?

Ø A user Ø An active object Ø A person Ø A system Ø Must be external to the described system

Ø What are the Applications/Uses? Ø What are the relations among

Use Cases Ø Extends: Extend an existing

use case (Inheritance)

Ø Uses: Reuse of an existing

use case (Sharing)

  • Prof. U. Aßmann

Action Oriented Design

Ø Which

Ø Users Ø External systems Ø Use Ø Need

Ø The system for which tasks? Ø Are tasks or relations to

complex?

slide-32
SLIDE 32

Refinement Service Station

Ø We introduce an abstraction of the services

  • Prof. U. Aßmann

Action Oriented Design

Parking Refueling Maintenance Billing Services Customer Manager Credit Card System Preventive Maintenance

slide-33
SLIDE 33

Second Refinement Service Station

  • Prof. U. Aßmann

Action Oriented Design

Parking Refueling Maintenance Billing Services Customer Manager Credit Card System Printer System Accounting Services Preventive Maintenance

slide-34
SLIDE 34

Third Refinement Service Station

Ø The <<includes>> relationship allows for decomposition of a use

  • case. <<includes>> is a form of <<part-of>>
  • Prof. U. Aßmann

Action Oriented Design

Inspection

Customer Manager

Diagnosis Therapy

Technician initiates

Recording Efforts

Accounting Services

Maintenance

<<includes>>

slide-35
SLIDE 35

35

Consistency Checking Check List Use Case Diagrams

Ø One diagram

Ø Clarity Ø Simplicity Ø Completeness Ø Match the stories of the customer? Ø Missing actors?

Ø Several diagrams

Ø Which actions occur in several diagrams? Are they specified

consistently?

Ø Should actors from shared actions be replicated to other UCD?

  • Prof. U. Aßmann

Action Oriented Design

slide-36
SLIDE 36

How To Go On from a Use Case Diagram

Ø There are several ways how to reach a design from a use case

diagram Ø Hierarchical refinement of the actions into UCD of second level, yielding

a reducible specification

Ø Disadvantage of UCD: Hierarchical refinement is sometimes difficult,

because new actors have to be added

Ø Leads to a correction of the top-level UCD Ø Action tree method: action-oriented method to refine the use case

actions with an action tree

Ø Collaboration diagram method: object-oriented method to analyse paths

in the use case diagram with communication (collaboration) diagrams (see later)

  • Prof. U. Aßmann

Action Oriented Design

slide-37
SLIDE 37

Hierarchical Refinement of a Use Case

Ø Often, new actors have to be added during refinement

  • Prof. U. Aßmann

Action Oriented Design

Technician

Evaluate inspection data Consult

  • ther

experts

Technician

Consult manual Diagnosis Diagnosis

new actor!!

slide-38
SLIDE 38

Deriving an Function Tree from a Use Case

Ø DomainTransformation: From a UCD, set up a function or action

tree Ø <<includes>> expresses a part-of hierarchy of function

Ø Refinement: Refine the functions by decomposition

  • Prof. U. Aßmann

Action Oriented Design

Inspection Diagnosis Therapy Watching Inspect Error codes Maintenance Recording Efforts

Combine inspection results Consult

  • ther

experts

..other..

slide-39
SLIDE 39

Benefits of Use Cases

Ø Use cases are good for

Ø Documentation Ø Communication with customers and designers -> Easy Ø Are started for the first layout of the structural model Ø To find classes, their actions, and relations Ø In eXtreme Programming (XP), use cases are called „stories“ Ø which are written down on one muddy card Ø collected Ø and implemented one after the other Ø XP does not look at all use cases together, but implements one after the

  • ther
  • Prof. U. Aßmann

Action Oriented Design

slide-40
SLIDE 40

The End

  • Prof. U. Aßmann

Modular Design 42