func5 - Modularity: Functions Chapter 4 Introduction...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction Modularity is an important part of the algorithm/program design process. Most algorithms solve complicated problems that are best understood and solved in pieces. Modularity allows the designer to abstract the various pieces needed to solve the problem into manageable size tasks. Modularity Subalgorithms are used to simplify the algorithm design and understanding. This is not just a “available option”, but the core of good algorithm design. Algorithms that do not feature modularity are low abstraction, hard to understand, and hard to debug. Modularity must be incorporated into any well designed algorithm. A Hierarchy of Abstraction Each subalgorithm handles a single logical “chunk” of the solution. The “main” algorithm coordinates the overriding logic. Graphical representation of abstraction featuring modularity It is abstraction because we are “considering the essence” (each task) “apart from the embodiment” (its component parts). Modularity: Functions - 1 Modularity: Functions – Chapter 4 Main algorithm Task 1 Task 2 Task 3 Sub-task 2.1 Sub-task 2.2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
It is a hierarchy of abstraction because we’re doing this at multiple levels: main, tasks, sub-tasks, sub-tasks of sub-tasks, etc. The details are hidden in the tasks and sub-tasks. Advantages of Modularity The details of the algorithm are hidden in the subalgorithms. This enhances understanding the algorithms by hiding obscure details. Makes the algorithm easier to write by reducing the complexity. Saves time, space, and effort. Modules can be called from many different places within an algorithm. Rather than repeating the task, you simply call the same task again. Sort of like speed-dial on your phone. Permits the reuse of logic. If properly designed, modules can be reused across different algorithms. All that is required is that the different algorithms need the same sub-task to be performed. Enhances the ability to maintain and reuse the implemented algorithm. Module Interfaces An interface is the common boundary between two bodies or spaces. In algorithmic terms, the interface specifies how the module can be connected to the outside world (i.e., to other algorithms). Example Consider the problem of obtaining a list of names, sorting those names into alphabetical order, and finally printing out the sorted list of names. This problem can logically be broken into three separate tasks (modules); (1) An input module to read the list of names. (2) A module to sort the names. (3) An output module to print the sorted list of names. When considering the second module to sort the names, we can choose any sorting technique that we want and change it whenever we feel like it without affecting the rest of the algorithm. Modularity: Functions -
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

func5 - Modularity: Functions Chapter 4 Introduction...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online