Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

INTRODUCTION TO PROGRAMMING & ALGORITHMS

Chapter 4: - Programming Methodologies


4.1 Introduction
Programming Methodology can be defines as the approach to analyzing complex problems, planning for
software development and controlling the development process. The programming methodologies /
paradigms may differ in terms of the basic idea which relates to the program computation. There are
many types of programming methodologies prevalent among software developers.

4.2. Categories of Programming Methodologies


The Categories includes;
1) Structured Programming
2) Object Oriented Programing
3) Aspect-Oriented Programming (AOP)

Alternative
1) Imperative: the emphasis is on the operations intended as actions/commands/instructions that
change the state of the computation; the objects are functional to the computation;
2) Functional: the emphasis is on the operations intended as functions that compute results; the
objects are functional to the computation;
3) object oriented: the emphasis is on the objects, which as a whole represent the domain of interest;
the operations are functional to the representation.

4.2. 1. Structured Programming


Structured programming involves building of programs using small modules. The modules are easy to
read and write. In structured programming, the problem to be solved is broken down into small tasks that
can be written independently. Once written, the small tasks are combined together to form the complete
task.
In structured programming, the approach to develop the software is process-centric or procedural. The
software is divided into procedures or modules, based on the overall functionality of the software. As a
result, the procedures and modules become tightly interwoven and interdependent. Thus, they are not re-
usable. C, COBOL and Pascal are examples of structured programming languages.

a) Procedural Programming: Problem is broken down into procedures, or blocks of code that
perform one task each. All procedures taken together form the whole program. It is suitable only
for small programs that have low level of complexity. Example − For a calculator program that
does addition, subtraction, multiplication, division, square root and comparison, each of these
operations can be developed as separate procedures. In the main program each procedure would
be invoked on the basis of user’s choice.
b) Functional Programming: Here the problem, or the desired solution, is broken down into
functional units. Each unit performs its own task and is self-sufficient. These units are then
stitched together to form the complete solution. Example − A payroll processing can have
functional units like employee data maintenance, basic salary calculation, gross salary
calculation, leave processing, loan repayment processing, etc.

Intro to Programming. Chapter 4: - Programming Methodologies Page 1


c) Logical Programming: Here the problem is broken down into logical units rather than functional
units. Example: In a school management system, users have very defined roles like class teacher,
subject teacher, lab assistant, coordinator, academic in-charge, etc. So the software can be divided
into units depending on user roles. Each user can have different interface, permissions, etc.

4.2.2. Object-Oriented Programming (OOP),


OOP focuses on developing the software based on their component objects. In OOP the software is
broken into components not based on their functionality, but based on the components or parts of the
software. Each component consists of data and the methods that operate on the data. The components
interact with each other to provide the functionality of the software. The components are complete by
themselves and are re-usable. Object-oriented programming (OOP) is a programming language model
organized around "objects" rather than "actions" and data rather than logic. The terms that are commonly
associated with object-oriented programming are as follows:
1) Class is the basic building block in object-oriented programming. A class consists of data attributes
and methods that operate on the data defined in the class.
2) Object is a runtime instance of the class. An object has a state, defined behavior and a unique
identity. The state of the object is represented by the data defined in the class. The methods defined
in the class represent object behavior. A class is a template for a set of objects that share common
data attributes and common behavior.
3) Abstraction, Encapsulation, Inheritance and Polymorphism are the unique features of object-
oriented software.
4) Abstraction allows dealing with the complexity of the object. Abstraction allows picking out the
relevant details of the object, and ignoring the non-essential details. Encapsulation is a way of
implementing abstraction.
5) Encapsulation means information hiding. The encapsulation feature of object-oriented software
hides the data defined in the class. Encapsulation separates implementation of the class from its
interface. The interaction with the class is through the interface provided by the set of methods
defined in the class. This separation of interface from its implementation allows changes to be
made in the class without affecting its interface.
6) The Inheritance feature of object-oriented software allows a new class, called the derived class, to
be derived from an already existing class known as the base class. The derived class (subclass)
inherits all data and methods of the base class (super class). It may override some or all of the data
and methods of the base class or add its own new data and methods.
7) Polymorphism means, many forms. It refers to an entity changing its form depending on the
circumstances. It allows different objects to respond to the same message in different ways. This
feature increases the flexibility of the program by allowing the appropriate method to be invoked
depending on the object executing the method invocation call.

C++ and Java are object-oriented programming languages.

4.2.3. Aspect-Oriented Programming (AOP)


Aspect-oriented programming is a new programming paradigm that handles the crosscutting concerns of
the software. The crosscutting concerns are the global concerns like logging, authentication, security,
performance, etc., that do not fit into a single module or related modules. In OOP, the business logic or

Intro to Programming. Chapter 4: - Programming Methodologies Page 2


core concern is encapsulated in well-defined classes. However, the code for implementing crosscutting
concerns is intertwined with a number of related classes or modules and gets scattered in the different
classes of the software.

AspectJ and AspectC are examples of aspect-oriented programming languages.

4.3 Approaches to Programming


Software developers may choose one or a combination of more than one of these methodologies to
develop a software. After having selected a suitable programming methodology / paradigm for the
program to be written, the coding of the logic of a program has to be done in a computer programming
language. For the purposes of coding, the programmer checks the requirements and suitability of the task,
and selects from among the programming languages available for the selected programming paradigm.

For each of the methodologies discussed, problem has to be broken down into smaller units. To do this,
developers use any of the following two approaches
1) Top-Down Approach
2) Bottom-up Approach

4.3.1. Top-down approach


A top-down approach (is also known as step-wise design) is essentially the breaking down of a system to
gain insight into its compositional sub-systems. In a top-down approach an overview of the system is
formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in yet
greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to
base elements. A top-down model is often specified with the assistance of "black boxes", these make it
easier to manipulate. However, black boxes may fail to elucidate elementary mechanisms or be detailed
enough to realistically validate the model.

Top-down-design starts with a description of the overall system and usually consists of a hierarchical
structure which contains more detailed descriptions of the system at each lower level. The lower level
design details continue until further subdivision is no longer possible, i.e., until the system is described in
terms of its "atomic" parts. This method involves a hierarchical or tree-like structure for a system as
illustrated by the following diagram:

Intro to Programming. Chapter 4: - Programming Methodologies Page 3


At the top level, we have that part of the system which deals with the overall system; a kind of system
overview or main top-level module.

Top down programming method process


1) Define exactly what data the program will get and what it has to do with them.
2) If the task is simple enough, write the program code.
3) Otherwise, split the task into smaller parts and define exactly the duty of each part and interface to the
rest of the program.
4) Repeat the steps 1–4 separately for each subtask.

Advantages of the Top-Down Design Method


1) It is easier to comprehend the solution of a smaller and less complicated problem than to grasp the
solution of a large and complex problem. Separating the low level work from the higher level
abstractions leads to a modular design. Modular design means development can be self contained.
Much less time consuming (each programmer is only involved in a part of the big project).
2) It is easier to test segments of solutions, rather than the entire solution at once. This method allows
one to test the solution of each sub-problem separately until the entire solution has been tested.
3) It is often possible to simplify the logical steps of each sub-problem, so that when taken as a whole,
the entire solution has less complex logic and hence easier to develop. A simplified solution takes less
time to develop and will be more readable.
4) The program will be easier to maintain. If errors occur in the output it is easy to identify the errors
generated from each of the modules / sub-programs of the entire program.

4.3.2. Bottom-up approach


This approach is the piecing together of systems to give rise to grander systems, thus making the original
systems sub-systems of the emergent system. In a bottom-up approach the individual base elements of the
system are first specified in great detail. These elements are then linked together to form larger
subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is
formed.

Bottom-up emphasizes coding and early testing, which can begin as soon as the first module has been
specified. This approach, however, runs the risk that modules may be coded without having a clear idea of
how they link to other parts of the system, and that such linking may not be as easy as first thought. Re-
usability of code is one of the main benefits of the bottom-up approach

4.4. Programming Aims and Program Characteristics


Good programming principles and practice aim at producing a program with the following characteristics;
1) Reliability: the program can be depended upon always to do what it is supposed to do
2) Maintainability: the program will be easy to change or modify when the need arises
3) Portability: the program will be transferable to a different computer with a minimum modification.
4) Readability: the program will be easy for a programmer to read and understand.
5) Performance: the program causes the tasks to be done quickly and efficiently.
6) Storage saving: the program is not allowed to be unnecessarily long
7) User friendly − Program interface, clickable links and icons, etc. should be user friendly.

Intro to Programming. Chapter 4: - Programming Methodologies Page 4


8) Structural: To develop a program, the task must be broken down into a number of subtasks. These
subtasks are developed independently, and each subtask is able to perform the assigned job without
the help of any other subtask. If a program is developed structurally, it becomes more readable, and
the testing and documentation process also gets easier.
9) Efficiency: As the processing power and memory are the most precious resources of a computer, a
program should be laid out in such a manner that it utilizes the least amount of memory and
processing time.
10) Flexibility: A program should be flexible enough to handle most of the changes without having to
rewrite the entire program.
11) Machine Independence- Program should be machine independent. Program written on one system
should be able to execute on any other without any changes.
12) Cost Effectiveness- Cost Effectiveness is the key to measure the program quality. Cost must be
measured over the life of the program and must include both cost and human cost of producing these
programs.
13) Generality: Apart from flexibility, the program should also be general. Generality means that if a
program is developed for a particular task, then it should also be used for all similar tasks of the same
domain.
14) Documentation: Documentation is one of the most important components of an application
development. Even if a program is developed following the best programming practices, it will be
rendered useless if the end user is not able to fully utilize the functionality of the application. A well-
documented application is also useful for other programmers because even in the absence of the
author, they can understand it.
15) The program should not have hard-coded input values. This implies that it should not be written to
work for a particular input value, but must be a general program (also called generic program) that
accepts input from the user.
A program comprising of the above features is generally characterized as a good program.
4.5. Program Instructions
A computer can do many things, but at a very basic level, programs consists of the following types of
instructions:
1) Input: get data from the keyboard or from some file or other device
2) Output: write
3) Math: perform some simple calculation, like addition and multiplication
4) Logical operations: compare values to make decisions
5) Conditional execution: check some condition and execute one sequence of statements or another
6) Repetition: repeat some sequence of operations, usually with some variation

4.6. Program Errors


There are three types of errors that occur in programs:
1) Syntax errors: these occur when the program is not written according to the rules of the language.
2) Runtime errors: these occur with programs that, even though they are syntactically correct, they
might execute instructions that violate some other rules of the language or some other set condition.
3) Semantic errors: these are the cases in which a program might run without generating error
messages, but it will not do the right thing.

Intro to Programming. Chapter 4: - Programming Methodologies Page 5

You might also like