Function oriented design


Published on


Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Function oriented design

  1. 1. Function-Oriented Design Module 3 Sangeetha Jose Lecturer in IT, Govt. Engg. College Idukki
  2. 2. Design <ul><li>A process to design (verb) </li></ul><ul><li>Result of the design process (noun) </li></ul>
  3. 3. Different levels… <ul><li>System design or top-level design (modular level) </li></ul><ul><li>Detailed design (Internal design of the module) </li></ul>
  4. 4. Design methodology <ul><li>… .is a systematic approach to create a design by applying of a set of techniques and guidelines </li></ul><ul><li>Input – specifications of the system to be designed </li></ul><ul><li>Output – system design </li></ul>
  5. 5. Object Oriented Design vs Function Oriented Design <ul><li>Object - oriented : modules in the design represent data abstraction </li></ul><ul><li>Function - oriented : consists of module definitions, with each module supporting a functional abstraction </li></ul><ul><li>Function-oriented design views a system as a set of modules with clearly defined behavior that interact with each other in a clearly defined manner to meet the system's requirements. </li></ul>
  6. 6. Design Objectives <ul><li>The goal of software design is to find the best possible design that meets your needs </li></ul><ul><li>You may have to explore different designs </li></ul><ul><li>Unfortunately, evaluation criteria for a design are often subjective and non-quantifiable </li></ul>
  7. 7. <ul><li>Major criteria to evaluate a design </li></ul><ul><ul><li>Correctness </li></ul></ul><ul><ul><ul><li>A software design is correct if a system built precisely according to the requirements of the system </li></ul></ul></ul><ul><ul><ul><li>A design should be verifiable (does an implementation match the design), complete (does the design address its specified requirements) and traceable (all design elements can be traced back to specific requirements) </li></ul></ul></ul><ul><ul><li>Efficiency </li></ul></ul><ul><ul><ul><li>Does the design efficiently make use of scarce resources: such as memory on a wireless sensor </li></ul></ul></ul><ul><ul><li>Maintainability and Simplicity </li></ul></ul><ul><ul><ul><li>How easy is it for the design of a system to be understood? </li></ul></ul></ul><ul><ul><ul><li>Simpler designs make it easy for a developer to understand and then maintain the system </li></ul></ul></ul><ul><ul><li>Cost </li></ul></ul><ul><ul><ul><li>Does the design help to reduce costs in later phases of software development? </li></ul></ul></ul><ul><ul><ul><li>Can one design achieve the same quality as another design while reducing costs? </li></ul></ul></ul>
  8. 8. Problem analysis Vs Design Principles <ul><li>Constructing a model of problem domain </li></ul><ul><li>Model depends on the system </li></ul><ul><li>Model is used to understand the problem </li></ul><ul><li>Constructing a model of solution domain </li></ul><ul><li>System depends on the model </li></ul><ul><li>Model is used for optimization </li></ul>
  9. 9. Design Principles <ul><li>Problem Partitioning and Hierarchy </li></ul><ul><li>Abstraction </li></ul><ul><li>Modularity </li></ul><ul><li>Top-Down and Bottom-Up Strategies </li></ul>
  10. 10. Problem Partitioning and Hierarchy <ul><li>Divide and Conquer </li></ul><ul><li>Decompose system into smaller and smaller pieces </li></ul><ul><ul><li>Ideally, each piece can be solved separately </li></ul></ul><ul><ul><li>Ideally, each piece can be modified independent of other pieces </li></ul></ul><ul><li>Reality: each piece must communicate with other pieces </li></ul><ul><ul><li>This communication implies a certain cost </li></ul></ul><ul><ul><li>At some point the cost is more than the benefit provided by the individual pieces </li></ul></ul><ul><ul><li>At this point, the decomposition process can stop </li></ul></ul>
  11. 11. Abstraction <ul><li>Abstraction is a powerful concept used in all engineering disciplines </li></ul><ul><li>It is a tool that permits a developer to consider a component in terms of the services (behaviors) it provides without worrying about the details of its implementation </li></ul>
  12. 12. Contd… <ul><li>Abstraction is an excellent tool for creating a hierarchical understanding of a system's functionality </li></ul><ul><li>In design contexts, you might see references to two “types” of abstraction </li></ul><ul><ul><li>functional abstraction: a module is specified by the functions it performs </li></ul></ul><ul><ul><li>data abstraction: a data structure is manipulated in terms of pre-defined operations; the implementation of the data structure is hidden from its users (only operations are visible) </li></ul></ul><ul><ul><li>The former is primarily used in functional design, the latter is used primarily in object-oriented design </li></ul></ul>
  13. 13. Modularity <ul><li>A system is considered modular if it consists of discreet components so that each component can be implemented separately, and a change to one component has minimal impact on other components </li></ul><ul><li>Helps in system repair and in system building </li></ul><ul><li>Each component needs to support a well-defined abstraction and have a specific interface that other modules use to interact with it </li></ul><ul><li>As Jalote says “Modularity is where abstraction and partitioning come together”. </li></ul>
  14. 14. Top-Down vs Bottom-Up Design <ul><li>A system consists of a set of components, which have subcomponents of their own </li></ul><ul><ul><li>The highest level component is the system itself, a concept we have seen when discussing context diagrams </li></ul></ul><ul><li>We can design such a hierarchy using either a top-down approach or a bottom-up approach </li></ul><ul><ul><li>In reality, we use both approaches and meet in the middle </li></ul></ul><ul><li>A top-down approach starts with the system as a whole, and using stepwise refinement , decomposes it into sub-components that exist at lower levels of abstraction </li></ul>
  15. 15. Contd… <ul><li>A bottom-up approach starts with primitive components that provide foundational services and using layers of abstraction builds the functionality the system needs until the entire system has been realized </li></ul><ul><li>A top-down approach is typically more useful in situations only if the specifications of the system are clearly known and application is being built from scratch (water fall model) </li></ul><ul><li>A bottom-up approach is thus more useful in situations in which a new application is being created from an existing (legacy) system (Iterative enhancement model) </li></ul>
  16. 16. Module <ul><li>It is a logically separable part of a program </li></ul><ul><li>It is a program unit that is discreet and identifiable with respect to compiling and loading </li></ul><ul><li>Can be a function, a procedure, a process or a package </li></ul>
  17. 17. Module-Level Concepts <ul><ul><li>Coupling </li></ul></ul><ul><ul><li>Cohesion </li></ul></ul>
  18. 18. Coupling <ul><li>“ how strongly” different modules are interconnected </li></ul><ul><li>By definition, </li></ul><ul><li>“ Coupling between modules is the strength of interconnections between modules or a measure of interdependence among modules” </li></ul><ul><li>An abstract concept and is not easily quantifiable </li></ul><ul><li>Highly coupled – strong interconnections </li></ul><ul><li>loosely coupled – weak interconnections </li></ul>
  19. 19. Contd… <ul><li>Factors influencing coupling are : </li></ul><ul><li> type of connection between modules </li></ul><ul><li> the complexity of the interface </li></ul><ul><li> the type of information flow between modules </li></ul><ul><li>Minimize the number of interfaces per module and the complexity of each interface </li></ul><ul><li>Depends up on the type of information flow, coupling varies </li></ul><ul><li>Data Flow – Minimal </li></ul><ul><li>Hybrid – Maximum (data and control) </li></ul>
  20. 20. Factors affecting coupling
  21. 21. Cohesion <ul><li>Cohesion is the concept that tries to capture intra-module bonds </li></ul><ul><li>Shows how closely the elements of a module are related to each other. </li></ul><ul><li>Shows how tightly bound the internal elements of the module are to one another </li></ul><ul><li>Usually, greater the cohesion of each module in the system, the lower the coupling between module is. </li></ul><ul><li>cohesion: how focused is an object (or module, or function, or package, etc.) on a particular task or concern </li></ul><ul><ul><li>a highly cohesive object has attributes and behavior that relate only to one task or concern </li></ul></ul>
  22. 22. Levels of cohesion <ul><li>Coincidental Low </li></ul><ul><li>Logical </li></ul><ul><li>Temporal </li></ul><ul><li>Procedural </li></ul><ul><li>Communicational </li></ul><ul><li>Sequential </li></ul><ul><li>Functional High </li></ul>
  23. 23. Details… <ul><li>Coincidental Cohesion occurs when there is no meaningful relationship among the elements of a module. </li></ul><ul><li>Logical Cohesion: if there is some logical relationship between the elements of a module (input and output modules) </li></ul><ul><li>Temporal cohesion: same as logical cohesion, except that the elements are also related in time and are executed together (initialization, clean-up, termination) </li></ul><ul><li>Procedurally cohesive module contains elements that belong to a common procedural unit (loop or a sequence of decision statements) </li></ul>
  24. 24. Contd… <ul><li>Communicational cohesion has elements that are related by a reference to the same input or output data (may perform more than one function) </li></ul><ul><li>Sequential cohesion occurs when output of one forms the input to another. </li></ul><ul><li>In functional cohesion all the elements of the module are related to performing a single function (single function or single goal – “compute square root” or “sort the array”) </li></ul>
  25. 25. How does one determine the cohesion level of a module? <ul><li>Compound sentence : sequential or communicational cohesion </li></ul><ul><li>“ first”, “next”, “when”, “after” : sequential or temporal </li></ul><ul><li>“ edit all data” : logical cohesion </li></ul><ul><li>“ initialize” or “cleanup” : temporal cohesion </li></ul>
  26. 26. <ul><li>We aim to create systems out of highly cohesive, loosely coupled components… </li></ul>
  27. 27. Design Notations <ul><li>Structure charts </li></ul><ul><li>UML </li></ul>
  28. 28. Structure Charts <ul><li>A structure chart is a graphical representation of a system's structure; in particular, its modules and their interconnections </li></ul><ul><li>Each module is represented by a box </li></ul><ul><li>If A uses B, then an arrow is drawn from A to B </li></ul><ul><ul><li>B is called the subordinate of A </li></ul></ul><ul><ul><li>A is called the superordinate of B </li></ul></ul><ul><li>An arrow is labeled with the parameters received by B as input and the parameters returned by B as output </li></ul><ul><ul><li>Arrows indicate the direction in which parameters flow </li></ul></ul><ul><ul><li>Parameters can be data (shown as unfilled circles at the tail of a label) or control information (filled circles at the tail) </li></ul></ul>
  29. 29. The structure chart of the sort program
  30. 30. Supports Iteration and Branching
  31. 31. Types of Modules <ul><li>Input : A module that only produces information that is passed to its superordinate </li></ul><ul><li>Output : A module that only receives information from its superordinate for output to a device </li></ul><ul><li>Transform : A module that converts data from one format into another format, possibly generating entirely new information. </li></ul><ul><li>Coordinator : A module that manages the flow of data to and from different subordinates </li></ul><ul><li>Composite : Modules that combine one or more of the above styles are composite modules </li></ul>
  32. 32. Different types…
  33. 33. Design specification <ul><li>A designer must also create a textual specification for each module that appears in the system's structure </li></ul><ul><li>Design specification contains </li></ul><ul><li>1. Problem Specification </li></ul><ul><li>2. Major Data Structures </li></ul><ul><li>3. Modules and their Specifications </li></ul><ul><li>4. Design Decisions </li></ul>
  34. 34. Structured Design Methodology <ul><li>The structured design methodology (SDM) views a system as a transformation function that transforms specified inputs into specified outputs. </li></ul>
  35. 35. Factoring <ul><li>A key concept of SDM is factoring </li></ul><ul><li>Factoring is the process of decomposing a module so that the bulk of its work is done by its subordinates </li></ul><ul><li>SDM attempts to achieve a structure that is close to being completely factored </li></ul>
  36. 36. SDM Strategy <ul><li>The overall strategy of SDM is to identify the input and output streams of the system and the primary transformations that have to be performed to produce the output </li></ul><ul><li>High-level modules are then created to perform these major activities, which are later refined (factored) </li></ul><ul><li>There are four major steps in applying this strategy </li></ul><ul><ul><li>Restate the problem as a data flow diagram </li></ul></ul><ul><ul><li>Identify the input and output data elements </li></ul></ul><ul><ul><li>Perform first-level factoring </li></ul></ul><ul><ul><li>Perform additional factoring on input, output and transform branches created in the previous step </li></ul></ul>
  37. 37. Step 1: Restate the problem as a data flow diagram <ul><li>DFD represents how the data will flow in the system when it is built. </li></ul><ul><li>Data flow diagrams during design are focused on the solution domain </li></ul><ul><ul><li>What are the inputs and outputs of our system (as opposed to the inputs and outputs of the problem domain)? </li></ul></ul><ul><ul><li>What are the central transformations? </li></ul></ul>
  38. 38. Example 1: DFD for an ATM Back
  39. 39. Example 2: DFD for a word-counting program Back
  40. 40. Step 2: Identify the input and output data elements <ul><li>What we are looking for is the most abstract input elements (MAI) and the most abstract output elements (MAO) </li></ul><ul><li>The MAI elements are found by going as far as possible from physical inputs without losing the incoming nature of the data element </li></ul><ul><li>The MAO elements are found by identifying the data elements most removed from the physical outputs without losing the outgoing nature of the data element </li></ul>Figure1 Figure2
  41. 41. Step 3: First-Level Factoring <ul><li>First-level factoring is the first step towards converting the DFD into a structure chart </li></ul><ul><li>You start by creating a module that represents the software system (the main module) </li></ul><ul><ul><li>The main module acts as a coordinator module </li></ul></ul><ul><li>For each MAI data element, specify a subordinate input module that delivers these items to the main module </li></ul><ul><li>For each MAO data element, specify an output module </li></ul><ul><li>For each central transform, specify a subordinate transform module </li></ul><ul><ul><li>The inputs and outputs of these transform modules are specified in the DFD </li></ul></ul>
  42. 42. Example 1: First-Level Factoring of word-counting example
  43. 43. Example 2: First-Level Factoring of ATM example
  44. 44. Step 4: Perform Additional Factoring <ul><li>Now stepwise refinement is used to specify the sub-modules required to realize the functionality of the modules created in the previous step </li></ul><ul><li>For each input module: </li></ul><ul><ul><li>assume that it is in the main module </li></ul></ul><ul><ul><li>add input modules that takes its MAI data element closer to the raw input </li></ul></ul><ul><ul><li>add transform modules in order to transform the raw input into the desired MAI data element </li></ul></ul>
  45. 45. Example: additional factoring of the word count program
  46. 46. Contd… <ul><li>Output modules are treated in a similar fashion, this time working from MAO data elements to the raw output of the system </li></ul><ul><li>Central transforms are also factored in a stepwise manner until you have specified atomic modules that can be implemented directly </li></ul>
  47. 47. Example: additional factoring of the word count program
  48. 48. SDM Wrap-Up <ul><li>Each new module produced in step 4 can then be examined to see if additional factoring is necessary </li></ul>
  49. 49. Design Heuristics <ul><li>The strategy requires the designer to exercise sound judgment and common sense </li></ul><ul><li>Cohesion and coupling should be the primary guiding factors </li></ul><ul><li>A very high fan-out is not very desirable (control and coordinate more modules) </li></ul><ul><li>Fan-in should be maximized </li></ul><ul><li>Scope of effect of a decision should be subset of the scope of control. </li></ul>
  50. 50. Verification <ul><li>Designs should be checked for internal consistency and for completeness with respect to the SRS </li></ul><ul><li>If a formal design notation is used, then tools may be able to perform some of these checks ( Automated Cross Checking) </li></ul><ul><li>Otherwise, design reviews (as part of your inspection process) are required to ensure that the finished design is of high quality </li></ul>
  51. 51. Design Reviews <ul><li>To ensure “quality” of the design </li></ul><ul><li>Aim of design reviews – detecting errors in design </li></ul><ul><li>Review team – a member of both the system design team and the detailed design team, the author of the requirements document, the author responsible for maintaining the design document, and an independent software quality engineer. </li></ul>
  52. 52. Metrics <ul><li>To provide quantitative data to the management process </li></ul><ul><li>Cost and schedule metrics are needed for tracking the progress of the project </li></ul><ul><li>Size is always a product metric of interest </li></ul><ul><li>Size: Number of Modules x Average LOC expected per module </li></ul><ul><ul><li>Or you can generate LOC estimates for each individual module </li></ul></ul>
  53. 53. Metrics <ul><li>Quality metrics </li></ul><ul><ul><li>Simplicity – most important design quality attribute </li></ul></ul><ul><li>Complexity metrics </li></ul><ul><ul><li>Network Metrics </li></ul></ul><ul><ul><li>Stability Metrics </li></ul></ul><ul><ul><li>Information Flow Metrics </li></ul></ul>
  54. 54. Network Metrics <ul><li>Network metrics focus on the structure chart of a system </li></ul><ul><li>They attempt to define how “good” the structure or network is in an effort to quantify the complexity of the call graph </li></ul><ul><li>The simplest structure occurs if the call graph is a tree. </li></ul><ul><ul><li>As a result, the graph impurity (deviation of the tree) is defined as nodes - edges - 1 </li></ul></ul><ul><ul><li>In the case of a tree, this metric produces the result zero since there is always one more node in a tree than edges </li></ul></ul><ul><ul><li>This metric is designed to make you examine nodes that have high coupling and see if there are ways to reduce this coupling </li></ul></ul>
  55. 55. Stability Metrics <ul><li>Stability of a design is a metric that tries to quantify the resistance of a design to the potential ripple effects that are caused by changes in modules </li></ul><ul><li>The creators of this metric argue that the higher the stability of a design, the easier it is to maintain the resulting system </li></ul><ul><li>This provides a stability value for each particular module </li></ul><ul><li>In essence, the lower the amount of coupling between modules, the higher the stability of the overall system </li></ul>
  56. 56. Information Flow Metrics <ul><li>Information flow metrics attempt to define the complexity of a system in terms of the total amount of information flowing through its modules </li></ul><ul><li>Jalote discusses two information flow metrics and how they can be used to classify modules </li></ul>
  57. 57. Approach 1 <ul><ul><li>A module's complexity depends on its intramodule complexity and its intermodule complexity </li></ul></ul><ul><ul><li>intramodule complexity is approximated by the (estimated) size of the module in lines of code </li></ul></ul><ul><ul><li>intermodule complexity is determined by the total amount of information (abstract data elements) flowing into a module (inflow) and the total amount of information flowing out of a module (outflow) </li></ul></ul><ul><ul><li>The module design complexity Dc is defined as Dc = size * (inflow*outflow) 2 </li></ul></ul><ul><ul><li>The term (inflow*outflow) 2 refers to the total number of input and output combinations, and this number is squared since the interconnections between modules are considered more important to determining the complexity of a module than its code size </li></ul></ul>
  58. 58. Approach 2 <ul><ul><li>Approach 1 depends largely on the amount of information flowing in and out of the module </li></ul></ul><ul><ul><li>Approach 2 is a variant that also considers the number of modules connected to a particular module; in addition, the code size of a module is considered insignificant with respect to a module's complexity </li></ul></ul><ul><ul><li>The module design complexity Dc is defined as Dc = (fan_in * fan_out) + (inflow*outflow) </li></ul></ul><ul><ul><li>fan_in above refers to the number of modules that call this module, fan_out is the number of modules called by this module </li></ul></ul>
  59. 59. Classification <ul><ul><li>Neither of these metrics is any good, unless they can tell us when to consider a module “too complex” </li></ul></ul><ul><ul><li>To this end, an approach was developed to compare a module's complexity against the complexity of the other modules in its system </li></ul></ul><ul><ul><li>avg_complexity is defined as the average complexity of the modules in the current design </li></ul></ul><ul><ul><li>std_deviation is defined as the standard deviation in the design complexity of the modules in the current design </li></ul></ul><ul><ul><li>A module can be classified as error prone , complex , or normal using the following conditions </li></ul></ul><ul><ul><li>Dc is the complexity of a particular module </li></ul></ul><ul><ul><li>A module is error prone if Dc > avg_complexity + std_deviation </li></ul></ul><ul><ul><li>A module is complex if avg_complexity < Dc < avg_complexity + std_deviation </li></ul></ul><ul><ul><li>Otherwise a module is considered normal </li></ul></ul>