Top-down and bottom-up programming in software Engineering

Programming refers to the method of creating a sequence of instructions to enable the computer to perform a task. It is done by developing logic and then writing instructions in a programming language. A program can be written using various programming practices available. A programming practice refers to the way of writing a program and is used along with coding style guidelines. Some of the commonly used programming practices include top-down programming, bottom-up programming, structured programming, and information hiding.

                                               

Top-down Programming

Top-down programming focuses on the use of modules. It is therefore also known as modular programming. The program is broken up into small modules so that it is easy to trace a particular segment of code in the software program. The modules at the top level are those that perform general tasks and proceed to other modules to perform a particular task. Each module is based on the functionality of its functions and procedures. In this approach, programming begins from the top level of hierarchy and progresses towards the lower levels. The implementation of modules starts with the main module. After the implementation of the main module, the subordinate modules are implemented and the process follows in this way. In top-down programming, there is a risk of implementing data structures as the modules are dependent on each other and they nave to share one or more functions and procedures. In this way, the functions and procedures are globally visible. In addition to modules, the top-down programming uses sequences and the nested levels of commands.

Bottom-up Programming

Bottom-up programming refers to the style of programming where an application is constructed with the description of modules. The description begins at the bottom of the hierarchy of modules and progresses through higher levels until it reaches the top. Bottom-up programming is just the opposite of top-down programming. Here, the program modules are more general and reusable than top-down programming.

It is easier to construct functions in bottom-up manner. This is because bottom-up programming requires a way of passing complicated arguments between functions. It takes the form of constructing abstract data types in languages such as C++ or Java, which can be used to implement an entire class of applications and not only the one that is to be written. It therefore becomes easier to add new features in a bottom-up approach than in a top-down programming approach.

Structured Programming

Structured programming is concerned with the structures used in a computer program. Generally, structures of computer program comprise decisions, sequences, and loops. The decision structures are used for conditional execution of statements [for example, ‘if statement]. The sequence structures are used for the sequentially executed statements. The loop structures are used for performing some repetitive tasks in the program.

Structured programming forces a logical structure in the program to be written in an efficient and understandable manner. The purpose of structured programming is to make the software code easy to modify when required. Some languages such as Ada, Pascal, and dBase are designed with features that implement the logical program structure in the software code. Primarily, the structured programming focuses on reducing the following statements from the program.

  1. ‘GOTO’ statements.
  2. ‘Break’ or ‘Continue’ outside the loops.
  3. Multiple exit points to a function, procedure, or subroutine. For example, multiple ‘Return’ statements should not be used.
  4. Multiple entry points to a function, procedure, or a subroutine.

Structured programming generally makes use of top-down design because program structure is divided into separate subsections. A defined function or set of similar functions is kept separately. Due to this separation of functions, they are easily loaded in the memory. In addition, these functions can be reused in one or more programs. Each module is tested individually. After testing, they are integrated with other modules to achieve an overall program structure. Note that a key characteristic of a structured statement is the presence of single entry and single exit point. This characteristic implies that during execution, a structured statement starts from one defined point and terminates at another defined point.

 Information Hiding

Information hiding focuses on hiding the non-essential details of functions and code in a program so that they are inaccessible to other components of the software. A software developer applies information hiding in software design and coding to hide unnecessary details from the rest of the program. The objective of information hiding is to minimize complexities among different modules of the software. Note that complexities arise when one program or module in software is dependent on several other programs and modules.

Information hiding is implemented with the help of interfaces. An interface is a medium of interaction for software components that are using the properties of the software modules containing data. The implementation of interfaces depends on the syntax and process. Examples of interface include constants, data types, types of procedures, and so on. Interfaces protect other parts of programs when a software design is changed.

Generally, the interfaces act as a foundation to modular programming [top-down programming] and object-oriented programming. In object-oriented programming, interface of an object comprises a set of methods, which are used to interact with the objects of the software programs. Using information hiding, a single program is divided into several modules. These modules are independent of each other and can be used interchangeably in other software programs.

To understand the concept of information hiding, let us consider an example of a program written for ‘car’. The program can be organized in several ways. One is to arrange modules without using information hiding. In this case, the modules can be created as ‘front part’, ‘middle part’, and ‘rear part’. On the other hand, creating modules using information hiding includes specifying names of modules such as ‘engine’ and ‘steering’.

On comparison, it is found that modules created without using information hiding affect other modules. This is because when a module is modified, it affects the data, which does not require modification. However, if modules are created using information hiding, then modules are concerned only with specific segments of the program and not the whole program or other parts of the program. In our example, this statement means that the module ‘engine’ does not have any affect on the module ‘steering’.

In a top-down implementation, the implementation starts from the top of the hierarchy and proceeds to the lower levels. First the main module is implemented, then its subordinates are implemented, and their subordinates, and so on.

In a bottom-up implementation, the process is the reverse. The development starts with implementing the modules at the bottom of the hierarchy and proceeds through the higher levels until it reaches the top.

Top-down and bottom-up implementation should not be confused with top-down and bottom -up design. When we proceed top-down, for testing a set of modules at the top of the hierarchy, stubs will have to be written for the lower level modules that the set of modules under testing invoke. On the other hand, when we proceed bottom-up, all modules that are lower in the hierarchy have been developed and driver modules are needed to invoke these modules under testing.

Top-down versus bottom-up is also a pertinent issue when the design is not detailed enough. In such cases, some of the design decisions have to be made during development.

C++CServer Side ProgrammingProgramming

Bottom-Up Model is a system design approach where parts of the system are defined in details. Once these parts are designed and developed, then these parts or components are linked together to prepare a bigger component. This approach is repeated until the complete system is built. Advantage of Bottom-Up Model is in making decisions at very low level and to decide the re-usability of components.

Top-Down Model

Top-Down Model is a system design approach where design starts from the system as a whole. Complete System is then divided into smaller sub-applications with more details. Each part again goes through the top-down approach till the complete system is designed with all minute details. Top Down approach is also termed as breaking the bigger problem into smaller problems and solving them individually in recursive manner.

Following are the important differences between Bottom-Up Model and Top-Down Model.

Sr. No.KeyBottom-Up ModelTop-Down Model
1FocusIn Bottom-Up Model, the focus is on identifying and resolving smallest problems and then integrating them together to solve the bigger problem.In Top-down Model, the focus is on breaking the bigger problem into smaller one and then repeat the process with each problem.
2LanguageBottom-Up Model is mainly used by object oriented programming languages like Java, C++ etc.Top-Down Model is followed by structural programming languages like C, Fortran etc.
3RedundancyBottom-Up model is better suited as it ensures minimum data redundancy and focus is on re-usability.Top-down model has high ratio of redundancy as the size of project increases.
4InteractionBottom-Up model have high interactivity between various modules.Top-down model has tight coupling issues and low interactivity between various modules.
5ApproachBottom-up model is based on composition approach.Top-down model is based on decomposition approach.
6IssuesIn Bottom-Up, some time it is difficult to identify overall functionality of system in initial stages.In Top-Down, it may not be possible to break the problem into set of smaller problems.

Published on 28-Nov-2019 11:16:33

Video liên quan

Chủ Đề