Lecture 04-1 Wk4 - Topic 2 Low-Level Design - Software Design Concepts and Principles
Lecture 04-1 Wk4 - Topic 2 Low-Level Design - Software Design Concepts and Principles
Lecture 4
Modularity
• Modularity is about dividing an application into separately named parts called modules.
• Each module is integrated into the application and contributes to its overall work.
• Modularity helps manage the complexity of an application and makes it easier to understand, develop,
and test the application.
MODULARITY IN STRUCTURED APPROACH
• In the structured programming approach, a function can be considered a module.
• When we develop a large application, we do not write a single large main function to do all the work,
• i.e. we do not write a monolithic program - a program composed of a single module.
• Instead we write various functions to carry out different parts of the work. The main function then calls
these functions in the correct order to accomplish the overall work.
• Modularity is achieved through Modular / Functional / Hierarchical Decomposition.
• A modular decomposition design is shown in a Structure Chart.
CRITERIA FOR MODULAR DECOMPOSITION
• aim for Low Coupling: a module should be as independent as possible from other
modules or, in other words, it should be loosely coupled to other modules; it should
not have unnecessary dependencies on other modules to accomplish its purpose;
therefore aim for low degree of relatedness to other modules.
Cohesion
• When designing a function, we want each line in the function to directly relate to the
purpose of that function. If we have pieces of code within the function which do not
relate to the purpose of the function, we should pull out the unrelated code to form to a
new function.
• Note: The purpose of the function should be reflected in the name of the function.
Naming functions correctly is very important to improve readability of an application.
• High cohesion improves development and testing. It also improves readability (and
therefore, maintainability).
CRITERIA FOR MODULAR DECOMPOSITION
Coupling
• A function should have minimal dependence on other functions and be highly
independent, or in other words, they should have low coupling to other functions.
• Low coupling improves maintainability because a change in one function will have a
minimal effect on other functions. It also promotes reusability because independent
functions are more easily
CRITERIA FOR MODULAR DECOMPOSITION
- Example of Improving Program Design
• Look at function add2numbers().
• Each class should be responsible for (knows about and does) only a few related things –
this makes the class highly cohesive.
• Information and behaviour related to a responsibility should be placed within the same
class – this is the object-oriented concept of encapsulation.
Exercise 1
Consider the following payroll processing program.
It is a monolithic program, consisting of only one function.
Perform modular decomposition (focus on the report writing operations).
Produce a Structure Chart to represent the new design of the program.
Exercise 2
For the payroll processing program above, develop an object-oriented version.
• You are to identify the classes you need and assign responsibilities to them.
• Produce a Class Diagram to represent the design.