Software Design Main issues:  decompose system into parts  many attempts to measure the results  design as product  design as process ©2008 John Wiley.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

Quality of a Class Abstraction: Coupling & Cohesion Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
Software Design Main issues:  decompose system into parts  many attempts to measure the results  design as product  design as process.
N. Kokash, Software Engineering
Communication between modules, cohesion and coupling
Design Concepts and Principles
Modeling Main issues: What do we want to build How do we write this down ©2008 John Wiley & Sons Ltd. vliet.
Software Metrics and Design Principles. What is Design? Design is the process of creating a plan or blueprint to follow during actual construction Design.
Figures – Chapter 24.
March 25, R. McFadyen1 Metrics Fan-in/fan-out Lines of code Cyclomatic complexity Comment percentage Length of identifiers Depth of conditional.
Nov R. McFadyen1 Metrics Fan-in/fan-out Lines of code Cyclomatic complexity* Comment percentage Length of identifiers Depth of conditional.
Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering.
© Copyright 2011 John Wiley & Sons, Inc.
Design Metrics Software Engineering Fall 2003 Aditya P. Mathur Last update: October 28, 2003.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
Object-Oriented Metrics
March R. McFadyen1 Software Metrics Software metrics help evaluate development and testing efforts needed, understandability, maintainability.
1 Complexity metrics  measure certain aspects of the software (lines of code, # of if-statements, depth of nesting, …)  use these numbers as a criterion.
PVK-Ht061 Contents Introduction Requirements Engineering Project Management Software Design Detailed Design and Coding Quality Assurance Maintenance.
PVK-Ht051 Contents Introduction Requirements Engineering Project Management Software Design Detailed Design and Coding Quality Assurance Maintenance.
University of Toronto Department of Computer Science © 2001, Steve Easterbrook CSC444 Lec22 1 Lecture 22: Software Measurement Basics of software measurement.
Object-oriented Design CSCI 5801: Software Engineering.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Coupling and Cohesion Source:
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
Software Measurement & Metrics
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 15b: Product Metrics for Software Software Engineering: A Practitioner’s Approach, 6/e Chapter.
Product Metrics An overview. What are metrics? “ A quantitative measure of the degree to which a system, component, or process possesses a given attribute.”
SOFTWARE DESIGN Design Concepts Design is a meaningful engineering representation of something that is to be built It can be traced to a customer’s requirements.
Sommerville, Mejia-Alvarez, 2009Software Engineering, Slide 1 Software Design u Deriving a solution which satisfies software requirements.
Software Design Deriving a solution which satisfies software requirements.
Concepts of Software Quality Yonglei Tao 1. Software Quality Attributes  Reliability  correctness, completeness, consistency, robustness  Testability.
Cohesion and Coupling CS 4311
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
GRASP: Designing Objects with Responsibilities
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
An Automatic Software Quality Measurement System.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
CSc 461/561 Information Systems Engineering Lecture 5 – Software Metrics.
Measurement and quality assessment Framework for product metrics – Measure, measurement, and metrics – Formulation, collection, analysis, interpretation,
11 Software Design CSCU 411 Software Engineering.
Object Oriented Metrics
Software Engineering Object Oriented Metrics. Objectives 1.To describe the distinguishing characteristics of Object-Oriented Metrics. 2.To introduce metrics.
CS223: Software Engineering Lecture 21: Unit Testing Metric.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
SOFTWARE DESIGN & SOFTWARE ENGINEERING Software design is a process in which data, program structure, interface and their details are represented by well.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
1 Week 7 Software Engineering Spring Term 2016 Marymount University School of Business Administration Professor Suydam.
School of Business Administration
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
Software Metrics 1.
Course Notes Set 12: Object-Oriented Metrics
Coupling and Cohesion 1.
Design Characteristics and Metrics
Software Design Main issues: decompose system into parts
which satisfies software requirements
Software Design.
Object-Oriented Metrics
Design Metrics Software Engineering Fall 2003
Design Metrics Software Engineering Fall 2003
Improving the Design “Can the design be better?”
CS223: Software Engineering
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 9.
Software Metrics SAD ::: Fall 2015 Sabbir Muhammad Saleh.
Chapter 8: Design: Characteristics and Metrics
Presentation transcript:

Software Design Main issues:  decompose system into parts  many attempts to measure the results  design as product  design as process ©2008 John Wiley & Sons Ltd. vliet

Overview Introduction Design principles Design methods Conclusion 2 ©2008 John Wiley & Sons Ltd. vliet

Programmer’s Approach to Software Engineering 3 Skip requirements engineering and design phases; start writing code ©2008 John Wiley & Sons Ltd. vliet

Point to ponder Is this the same as eXtreme Programming? Or is there something additional in XP? 4 ©2008 John Wiley & Sons Ltd. vliet

Why this programmer’s approach? Design is a waste of time We need to show something to the customer real quick We are judged by the amount of LOC/month We expect or know that the schedule is too tight 5 ©2008 John Wiley & Sons Ltd. vliet

However,... The longer you postpone coding, the sooner you’ll be finished 6 ©2008 John Wiley & Sons Ltd. vliet

Up front remarks Design is a trial-and-error process The process is not the same as the outcome of that process There is an interaction between requirements engineering, architecting, and design 7 ©2008 John Wiley & Sons Ltd. vliet

Software design as a “wicked” problem There is no definite formulation There is no stopping rule Solutions are not simply true or false Every wicked problem is a symptom of another problem 8 ©2008 John Wiley & Sons Ltd. vliet

Design Principles 9 Abstraction Modularity, coupling and cohesion Information hiding Limit complexity Hierarchical structure ©2008 John Wiley & Sons Ltd. vliet

Abstraction procedural abstraction: natural consequence of stepwise refinement: name of procedure denotes sequence of actions 10 abstractionsubproblems time ©2008 John Wiley & Sons Ltd. vliet

Abstraction data abstraction: aimed at finding a hierarchy in the data 11 application-oriented data structures simpler data structure general data structures ©2008 John Wiley & Sons Ltd. vliet

Modularity structural criteria which tell us something about individual modules and their interconnections cohesion and coupling cohesion: a measure of the mutual affinity of the elements of a component; the degree of relatedness among elements within the module coupling: the strength of the connection between modules; the degree of interaction among modules 12 ©2008 John Wiley & Sons Ltd. vliet

Types of Cohesion 13 coincidental cohesion logical cohesion temporal cohesion procedural cohesion communicational cohesion sequential cohesion functional cohesion data cohesion (to cater for abstract data types) ©2008 John Wiley & Sons Ltd. vliet

Cohesion Definitions Coincidental: no apparent connection between elements Logical: elements perform tasks that can be classified under a broad, general category Temporal: elements linked by the time at which they are executed Procedural: elements are related by the order of their occurrence

Cohesion Definitions (cont.) Communicational: elements all use the same data set, but results of one stage of the process are not passed on to other stages Sequential: elements take on a production line interdependence Functional: every processing element is essential to the performance of a single function

How to determine the cohesion type? describe the purpose of the module in one sentence if the sentence is compound, contains a comma or more than one verb  it probably has more than one function: logical or communicational cohesion if the sentence contains time-related words like “first”, “then”, “after”  temporal cohesion if the verb is not followed by a specific object  probably logical cohesion (example: edit all data) words like “startup”, “initialize” imply temporal cohesion 16 ©2008 John Wiley & Sons Ltd. vliet

Types of Coupling 17 content coupling common coupling external coupling control coupling stamp coupling data coupling ©2008 John Wiley & Sons Ltd. vliet

Coupling Definitions Content – when one module uses or modifies code in another module Common – when modules reference a global data area Control – when one module passes a flag to direct the activity of another module Stamp – when information with some structural characteristics is passed Data – when information passed is unstructured

Coupling levels are technology dependent Data coupling assumes scalars or arrays, not records control coupling assumes passing of scalar data nowadays: – modules may pass complex data structures – modules may allow some modules access to their data, and deny it to others (so there are many levels of visibility) – coupling need not be commutative (A may be data coupled to B, while B is control coupled to A) 19 ©2008 John Wiley & Sons Ltd. vliet

strong cohesion & weak coupling  simple interfaces  simpler communication simpler correctness proofs changes influence other modules less often reusability increases comprehensibility improves 20 ©2008 John Wiley & Sons Ltd. vliet

Information Hiding 21 each module has a secret design involves a series of decisions: for each such decision, wonder who needs to know and who can be kept in the dark information hiding is strongly related to – abstraction: if you hide something, the user may abstract from that fact – coupling: the secret decreases coupling between a module and its environment – cohesion: the secret is what binds the parts of the module together ©2008 John Wiley & Sons Ltd. vliet

Point to ponder How many lines of code is this: #include #define NULL 0 main () { int i; for (i=0;i<10;i++) printf(%d”,i); } 22 ©2008 John Wiley & Sons Ltd. vliet

Complexity measure certain aspects of the software (lines of code, # of if-statements, depth of nesting, …) use these numbers as a criterion to assess a design, or to guide the design interpretation: higher value  higher complexity  more effort required (= worse design) two kinds: – intra-modular: inside one module – inter-modular: between modules 23 ©2008 John Wiley & Sons Ltd. vliet

intra-modular attributes of a single module two classes: – measures based on size – measures based on structure 24 ©2008 John Wiley & Sons Ltd. vliet

Sized-based complexity measures 25 counting lines of code – differences in verbosity – differences between programming languages – a:= b versus while p^ <> nil do p:= p^ Halstead’s “software science”, essentially counting operators and operands ©2008 John Wiley & Sons Ltd. vliet

Software science basic entities 26 n 1 : number of unique operators n 2 : number of unique operands N 1 : total number of operators N 2 : total number of operands ©2008 John Wiley & Sons Ltd. vliet

Example program public static void sort(int x []) { for (int i=0; i < x.length-1; i++) { for (int j=i+1; j < x.length; j++) { if (x[i] > x[j]) { int save=x[i]; x[i]=x[j]; x[j]=save } 27 operator, 1 occurrence operator, 2 occurrences ©2008 John Wiley & Sons Ltd. vliet

operator # of Occurrences public sort() int [] {} for {;;} if () = < … n 1 = … N 1 = ©2008 John Wiley & Sons Ltd. vliet

Example program public static void sort(int x []) { for (int i=0; i < x.length-1; i++) { for (int j=i+1; j < x.length; j++) { if (x[i] > x[j]) { int save=x[i]; x[i]=x[j]; x[j]=save } 29 operand, 2 occurrences ©2008 John Wiley & Sons Ltd. vliet

operand # of occurrences x length i j save 0 1 n 2 = N 2 = ©2008 John Wiley & Sons Ltd. vliet

Other software science formulas 31 size of vocabulary: n = n 1 + n 2 program length: N = N 1 + N 2 volume: V = N log 2 n level of abstraction: L = V*/ V approximation: L’ = (2/n 1 )(n 2 /N 2 ) programming effort: E = V/L estimated programming time: T ’ = E/18 estimate of N: N ’ = n 1 log 2 n 2 : n 2 log 2 n 2 for this example: N = 68, N ’ = 89, L =.015, L’ =.028 ©2008 John Wiley & Sons Ltd. vliet

Software science empirical studies: reasonably good fit critique: – explanations are not convincing – results from cognitive psychology used wrongly – is aimed at coding phase only; assumes this is an uninterrupted concentrated activity – different definitions of “operand” and “operator” 32 ©2008 John Wiley & Sons Ltd. vliet

Structure-based measures 33 based on – control structures – data structures – or both example complexity measure based on data structures: average number of instructions between successive references to a variable best known measure is based on the control structure: McCabe’s Cyclomatic Complexity ©2008 John Wiley & Sons Ltd. vliet

Example program public static void sort(int x []) { for (int i=0; i < x.length-1; i++) { for (int j=i+1; j < x.length; j++) { if (x[i] > x[j]) { int save=x[i]; x[i]=x[j]; x[j]=save } ©2008 John Wiley & Sons Ltd. vliet

Cyclomatic complexity e = number of edges (13) n = number of nodes (11) CV = e - n + 2 (4) = number of predicates + 1 = number of regions ©2008 John Wiley & Sons Ltd. vliet

Intra-modular complexity measures, summary for small programs, the various measures correlate well with programming time however, a simple length measure such as LOC does equally well complexity measures are not very context sensitive complexity measures take into account few aspects it might help to look at the complexity density instead (CV/LOC) 36 ©2008 John Wiley & Sons Ltd. vliet

System structure: inter-module complexity looks at the complexity of the dependencies between modules draw modules and their dependencies in a graph then the arrows connecting modules may denote several relations, such as: – A contains B – A precedes B – A uses B we are mostly interested in the latter type of relation 37 ©2008 John Wiley & Sons Ltd. vliet

The uses relation In a well-structured piece of software, the dependencies show up as procedure calls therefore, this graph is known as the call- graph possible shapes of this graph: – chaos (directed graph) – hierarchy (acyclic graph) – strict hierarchy (layers) – tree 38 ©2008 John Wiley & Sons Ltd. vliet

In a picture: 39 chaos strict hierarchy tree ©2008 John Wiley & Sons Ltd. vliet

Measurements 40 } size # nodes # edges width height ©2008 John Wiley & Sons Ltd. vliet

Deviation from a tree 41 strict hierarchy tree ©2008 John Wiley & Sons Ltd. vliet

Tree impurity metric complete graph with n nodes has n(n-1)/2 edges a tree with n nodes has (n-1) edges tree impurity for a graph with n nodes and e edges: m(G) = 2(e-n+1)/(n-1)(n-2) this is a “good” measure, in the measurement theory sense 42 ©2008 John Wiley & Sons Ltd. vliet

Desirable properties of any tree impurity metric m(G) = 0 if and only if G is a tree m(G 1 ) > m(G 2 ) if G 1 = G 2 + an extra edge if G 1 and G 2 have the same # of “extra” edges wrt their spanning tree, and G 1 has more nodes than G 2, then m(G 1 ) < m(G 2 ) m(G)  m(K n ) = 1, where G has n nodes, and K n is the (undirected) complete graph with n nodes 43 ©2008 John Wiley & Sons Ltd. vliet

Information flow metric tree impurity metrics only consider the number of edges, not their “thickness” Henri & Kafura’s information flow metric takes this “thickness” into account based on notions of local and global flow we consider a later variant, developed by Shepperd 44 ©2008 John Wiley & Sons Ltd. vliet

Shepperd’s variant of information flow metric there is a local flow from A to B if: – A invokes B and passes it a parameter – B invokes A and A returns a value there is a global flow from A to B if A updates some global structure and B reads that structure fan-in(M) = # (local and global) flows whose sink is M fan-out(M) = # (local and global) flows whose source is M complexity(M) = (fan-in(M) * fan-out(M)) 2 Weakness: all flows count the same 45 ©2008 John Wiley & Sons Ltd. vliet

Object-oriented metrics 46 WMC: Weighted Methods per Class DIT: Depth of Inheritance Tree NOC: Number Of Children CBO: Coupling Between Object Classes RFC: Response For a Class LCOM: Lack of COhesion of a Method ©2008 John Wiley & Sons Ltd. vliet

Weighted Methods per Class 47 measure for size of class WMC =  c(i), i = 1, …, n (number of methods) c(i) = complexity of method i mostly, c(i) = 1 ©2008 John Wiley & Sons Ltd. vliet

Depth of Class in Inheritance Tree DIT = distance of class to root of its inheritance tree DIT is somewhat language-dependent widely accepted heuristic: strive for a forest of classes, a collection of inheritance trees of medium height 48 ©2008 John Wiley & Sons Ltd. vliet

Number Of Children 49 NOC: counts immediate descendants higher values NOC are considered bad: – possibly improper abstraction of the parent class – also suggests that class is to be used in a variety of settings, which will make it more error prone. ©2008 John Wiley & Sons Ltd. vliet

Coupling Between Object Classes two classes are coupled if a method of one class uses a method or state variable of another class CBO = count of all classes a given class is coupled with high values: something is wrong all couplings are counted alike; refinements are possible 50 ©2008 John Wiley & Sons Ltd. vliet

More on CBO Although all couplings are considered equal, it is reasonable to say: – Access to state variables is worse than mere parameter passing – Access to elements of a foreign class is worse than access to elements of a superclass – Passing many complex parameters is worse than passing a few simple parameters – Messages that conform to Demeter’s Law are better than those which do not

Demeter’s Law The Law of Demeter is a generally accepted design heuristic for OO systems. It states that the methods of a class should depend only on the top-level structure of their own class. More specifically, in the context of a class C with method M, M should only send messages to – The parameters of C – The state variables of C – C itself

Response For a Class RFC measures the “immediate surroundings” of a class RFC = size of the “response set” response set = {M}  {Ri}, the set of messages that may potentially be executed if a message is sent to an object of class C. Messages are measured one level deep. 53 M1 M3 M2 R1 Larger values of RFC make comprehension of a class more difficult and increase test time and complexity.

Lack of Cohesion of a Method cohesion = glue that keeps the module (class) together if all methods use the same set of state variables: OK, & that is the glue if some methods use a subset of the state variables, and others use another subset, the class lacks cohesion LCOM = number of disjoint sets of methods in a class two methods in the same set share at least one state variable The preferred value for LCOM is ©2008 John Wiley & Sons Ltd. vliet

OO metrics WMC, CBO, RFC, LCOM most useful – Predict fault proneness during design – Strong relationship to maintenance effort The merits of DIT and NCO remain somewhat unclear Many OO metrics correlate strongly with size It remains questionable whether these metrics tell more than a plain LOC code. 55

OOAD Methods 56 three major steps: 1identify the objects 2determine their attributes and services 3determine the relationships between objects ©2008 John Wiley & Sons Ltd. vliet

(Part of) problem statement Design the software to support the operation of a public library. The system has a number of stations for customer transactions. These stations are operated by library employees. When a book is borrowed, the identification card of the client is read. Next, the station’s bar code reader reads the book’s code. When a book is returned, the identification card is not needed and only the book’s code needs to be read. 57 ©2008 John Wiley & Sons Ltd. vliet

Candidate objects 58 software library system station customer transaction book library employee identification card client bar code reader book’s code ©2008 John Wiley & Sons Ltd. vliet

Carefully consider candidate list eliminate implementation constructs, such as “software” replace or eliminate vague terms: “system”  “computer” equate synonymous terms: “customer” and “client”  “client” eliminate operation names, if possible (such as “transaction”) be careful in what you really mean: can a client be a library employee? Is it “book copy” rather than “book”? eliminate individual objects (as opposed to classes). “book’s code”  attribute of “book copy” 59 ©2008 John Wiley & Sons Ltd. vliet

Relationships From the problem statement: – employee operates station – station has bar code reader – bar code reader reads book copy – bar code reader reads identification card Tacit knowledge: – library owns computer – library owns stations – computer communicates with station – library employs employee – client is member of library – client has identification card 60 ©2008 John Wiley & Sons Ltd. vliet

Result: initial class diagram 61 ©2008 John Wiley & Sons Ltd. vliet

Usage scenario  sequence diagram 62 ©2008 John Wiley & Sons Ltd. vliet

Antipatterns 63 Patterns describe desirable behavior Antipatterns describe situations one had better avoid In agile approaches (XP), refactoring is applied whenever an antipattern has been introduced ©2008 John Wiley & Sons Ltd. vliet

Example antipatterns God class: class that holds most responsibilities Lava flow: dead code Poltergeist: class with few responsibilities and a short life Golden Hammer: solution that does not fit the problem Stovepipe: (almost) identical solutions at different places Swiss Army Knife: excessively complex class interface 64 ©2008 John Wiley & Sons Ltd. vliet

Conclusion Essence of the design process: decompose system into parts Desirable properties of a decomposition: coupling/cohesion, information hiding, (layers of) abstraction There have been many attempts to express these properties in numbers 65 ©2008 John Wiley & Sons Ltd. vliet