Chapter 3 Programming Techniques (PLT)
Chapter 3 Programming Techniques (PLT)
PROGRAMMING TECHNIQUES
1. INTRODUCTION:
Program is a series of instructions and procedures which made for perform the specific task. The programmer can
use any logic and method for develop the program. Programming technique is a logic, procedure and methodology of
the programming which used by the programmer to design the program easily and separately. The Programmer can
develop his/her program with ability to carry out specific sequence of calculations for a short period of time and
ability to make logical decisions and repetition of given set of instructions automatically without any bug or error.
These types of logical decisions or branching capabilities such as iteration control, selection control or decision
control or condition control are the programming techniques which coded by the programmer. The programming
technique also helps for the decision making. The programming techniques allow the programmer to divide the
programming tasks into sub tasks and use previously written block also. Most of the programming algorithms relay
the technique uses of iteration and condition branching. There are various techniques used by the programmer or
developer to make effective, errorless and versatile. Some of important techniques are described below:
1.Top down and bottom up design
2. Modular Programming
3. Structural Programming
4. Object oriented programming
First, the main program would be written and tested with three stubs Sub program A, Sub program B, Sub program
C. Next, subprogram A would be written and tested with two stubs Sub program D and Sub program E. Then it would
be tested with main program. Sub program B and Sub program C and their stubs would be developing in the same
way.
Advantages of Top-down approach:
It starts with the top level module and progresses downward to the lowest level module.
It allows a programmer to remain "on top of" a problem and view the developing solution in context. The
solution always proceeds from the highest levels down.
Separating the low –level work from high level concept leads to a modular design. Modular design means
development can be self-contained.
Projects become quite optimized as each developer applies his own knowledge and experience to individual
modules.
It is easy to visualize, provides sense of completeness and easy to access the progress at any stage.
Increased intellectual manageability and comprehension. And reduced debugging time.
Here, a large program divided into four sub modules. Each module encompasses a specific function within the
program. The function of each module can be different such as input, locate, update, print etc. This technique allows
several programmers to code simultaneously and decrease the debugging time. Function of each module can be
logically separated. Such functions can be initialization part, input, processing, output, error handling, closing
procedure etc. parts.
Advantages of modular design:
Some modules will be standard procedures used again and again in different programs or parts of the same
program.
Since module is small, it is simpler to understand, code, easier to test and debug, especially and documented.
Program maintenance becomes easier because the affected modules can be quickly identified and changed.
In a very large project, several programmers may be working on a single program. Using a modular approach,
the tasks can be distributed among programmers.
More experienced programmers can be given the more complex modules to write, and the junior programmers
can work on the simpler modules.
Modules can be tested independently, thereby shortening the time taken to get the whole program working.
If a programmer leaves part way through a project, it is easier for someone else to take over a set of self
contained modules.
A large project becomes easier to monitor and control.
There are three basic logical structures which can define a programming as structure programming technique using
program.
Three basic logical structures (Types of logics):
1. Simple Sequential Structure or Linear Structure
2. Conditional or Selection or Decisional Structure
3. Looping Structure or Iterative Structure or Repetitive Structure
1. Simple Sequence Structure: It is a linear structure in which instructions or statements are executed
consecutively in a sequence. In this method the program prepared according to straight forward programming in
a sequential manner. This type of programming does not involve any decision making.
2. Conditional Structure: In this structure a condition is tested. The condition is followed by two alternative blocks
or program control paths. The selection of the path depends on the result of the test. If the condition is satisfied or
the truth, then first particular program is executed otherwise another or false particular program is executed.
2. Looping Structure: In this technique every looping logics uses the condition factors for the finite time period.
This technique indicates that the part of program or statement can occur repeatedly. In this structure a condition
also is checked and executes the program till the satisfaction of the condition. If given condition is true then the given
program is executed for certain number of tome until the condition is satisfied. If the condition is false then the given
program 1 is not executed.
In a loop and operation or a setoff operations are repeated as long as (while) condition is satisfied. The basic form of
repetition is termed WHILE in the literature of structured programming.
Advantages of Structured programming:
The problem at hand is analysed or broken down into major components, each of which is again broken down if
necessary.
Each module has one entry point and one exit point.
Two-way decision statements are based on IF-THEN, IF-THEN-ELSE, and nested IF statements.
Loops are based on the consistent use of WHILE-WEND and FOR-NEXT.
The data pass from the main module or root module or boss module to the lower level module ,there need to call or
invoke the lower level module. Generally, the first module is main module and it said to call or invoke the lower level
module. In the Root module data or parameter or address can be passed to the lower level module.
Control items are used to direct program control and show the activities or errors of the module or conditions of the
modules and sub modules. The root module passes the control down at the lower level modules. The control is
always returned to the invoking module and as a finished module should always terminate at the root.
Here, in the diagram GET CUSTOMER DETAIL named module invokes the module FIND CUSTOMER DEATIL named
module by passing Customer A/C number. The flag Account No. OK is sent to the calling module to confirm that the
requested account number does have a valid account name. Here control couple is shown by black filled in circle on
the tail of arrow.
Cohesion:
Cohesion is concern with examining the internal activities of a single module. It is a measure of functional strength of
a module. Generally one module should perform only one task. It is the degree to which module is concerned with a
single task. A module having high cohesion and low coupling is said to be functionally independent of other modules.
By the term functional independence, we mean that a cohesive module performs a single task or function. It refers to
how clearly define a particular module or procedure. A module with high cohesion performs one or few things
exceedingly well. It is the concept which tries to capture relation with intra-module. Cohesion of a module represents
how tightly bounded the internal elements of the module one to another. It is a module activity that perform all the
operation here, suppose inputs or outputs .In such situation if we want to input or output a particular record , we
have to convey this to the module. Within the cohesion every module try to perform many tasks-validate input,
process data, output results individually them. There are several levels (Types) of cohesion such as functional level,
sequential level, temporal level, procedural level, logical level etc. which defined in brief.
Functional Cohesion: A module is called functionally cohesion when it consists of data items that all contribute
to the execution of one task. These types of modules are overcomes single-minded.
Sequential Cohesion: A module is called sequentially cohesion when it consist the elements with the sequence
of actions. In this activity within the module are correlated to earn the specified task of the module.
Communicational Cohesion: This is the module that performs a number of activities on the same input or
output data. For example: entered data Customer Ac/No. may be used within one module to find the Customer
Name, Address, Contact No., Balance etc.
Procedural Cohesion: A module is called procedurally cohesion whose internal activities seem to bear little
relationship to each other. In this type of module, control passes between each activities to another and may be
organized in sequence order.
Prepared by: N.P.BHUSAL 6 Email ID: smcnpbhusl@gmail.com
PROGRAMMING LOGIC AND TECHNIQUES
Temporal Cohesion: A module is called procedurally cohesion where every activities tent to occur at the same
time. In this model activities are more closely related to those in other modules also.
Logical Cohesion: A module is called procedurally cohesion where the selection of activities within a module is
directed form the outside. The module contains activities of general kind, which is selected through the common
interface.
Coincidental Cohesive: A module is called procedurally cohesion where the activities have no temporal, no
procedural or logical connection. The modules have probably been created by cutting up longer program into a
modularized design.
Coupling:
Coupling is a link and connection between two or more modules. Coupling is an activity which consists of
interconnections between modules and measure interdependence among the modules. Highly coupled modules are
joined by strong interconnection relations while loosely coupled modules have weak interconnection relations
whenever individual modules have no any relation of connectivity. Coupling increases with the complexity of the
interface between modules because if any procedure has parameters and there need to call the items then there
need the communication with other module so, there, coupling is considered highest if the data is hybrid i.e. some
data items and some data control item are passed between modules. Coupling is reduced when the relationships
among the elements in different modules are minimized. There are several forms of coupling which are described in
brief.
Data Coupling: A module is called data coupling where performs the activity of exchange of data items between
the modules. This is necessary for module control and communication. Data coupling is when modules share
data through, for example, parameters. Each datum is an elementary piece, and these are the only data shared
(e.g., passing an integer to a function that computes a square root).
Stamp Coupling: A module is called Stamp coupling when a whole data structure is passed to a module and in
that structure there are data items which are irrelevant to the calling module. This activity introduces
dependencies between modules which are unrelated but structure should be passed. Two modules are stamped
coupled, if they communicate using a composite data item such as a record in PASCAL or a structure in C.
Common Coupling: A module is called Common coupling if any two modules refers to the same common data
area. These common data area are defined within the context of target programming language. Common
coupling can lead to problems in error rippling, maintenance and inflexibility.
Content Coupling: A module is called Content coupling if one module refers to the internal workings of the
others. This activity in modules produces systems which are virtually unmentionable.
Control coupling: It is a type of coupling in which one module communicates information to another module for
the explicit purpose of influencing the execution of the latter. It is the manner or degree by which one software
component influences the execution of another software component. It is the process in which one module is
controlling the flow of another, by passing it information on what to do (e.g., passing a what-to-do flag).
Program development models are the particular hypothetical and situational description of a complex entity or
process of the program. The evolution of software or program development represent the cycle of activities involved
in the development to use and the maintenance of the software or program system. The program development life
cycle depicts the significant phases or activities of a program project form conception until the product is complete.
It specifies the relationship between program or project phases, including transitions criteria, feedback mechanisms,
Prepared by: N.P.BHUSAL 7 Email ID: smcnpbhusl@gmail.com
PROGRAMMING LOGIC AND TECHNIQUES
reviews etc. Typically a program development life cycle model addresses the every phases of the program or
software i.e. requirement phase , design phase, coding phase, implement phase, debugging and testing phase ,
operational and maintenance phase and so on. It is a matter of picking the right tool for the job. A developer or
programmer can follow any suitable model to complete his /her program. This is also called a development process
layout. A development process is a set of activities which are performed according to specified order to get desired
output. It is an abstract representation of a development process.
The Prototype model is the model that serves as a mechanism for identifying the program requirements. Sometimes
the programmer does not sure about the efficiency of handle all the situations. These many other different situations
are common for a large and complex system for which there is no manual system exists. To develop a program or
software product for such problems prototyping model is used. This is the model begins with requirement gathering.
The developer defines over all objectives and contents and also identifies the area for the system. This model
provides feedback about what is correct, area to be modified, features to be added then the final requirements are
refined and the program developed. It is well suited where the requirements are hard to determine. This type of
mostly needed for develop new programming system or new project system where it is not clear that the constraints
can be met. Instead of concentrating core documentation, more effort is placed in the actual program or software
development. It saves the time in creating a program or software than traditional model. This type of model used
technique to perform the required changes to a program based on the feedback of client or user. This model using
softwares or programs maintained according to the clients or customers or users satisfaction. It is an iterative, trial-
and-error process that takes place between the developers and the users. Therefore, prototyping is an excellent
technique for reducing risks associated with a program or project. Experience of developing prototype reduces the
cost of later phases of the product development.
This model is mostly used in large, expensive and complex projects. It is reasonable to use the spiral model in project
where business goals are unstable but architecture must be realized well enough to provide high coding and stress
ability. It is a system development method (SDM) which used in information technology also. This model is intended
for large, experienced and complicated program system. It can be considered as a generalization of the prototyping
model. The spiral model is the most general. Most life cycle models can in fact be derived as special instances of the
spiral model. This spiral model uses an evolutionary approach to software engineering and it uses prototyping as a
risk reduction mechanism and also it maintains the systematic approach suggested by classic life. For example, the
Spiral Architecture Driven Development is the spiral based SDLC which shows the possible way how to reduce a risk
of non-effective architecture with the help of spiral model in conjunction with the best practices from other models.
It allows for the development of the product to be performing using a prototyping technique or rapid application
development through the use of 4th Generation languages and development tools.
or
1. Spiral Quadrant: Determine objectives, alternatives and constraints:
Objectives: functionality, performance, hardware/software interface, critical success factors, etc.
Alternatives: build, reuse, buy, sub-contract, etc.
Constraints: cost, schedule, interface, etc.
2. Spiral Quadrant: Evaluate alternatives, identify and resolve risks:
Study alternatives relative to objectives and constraints
Identify risks (lack of experience, new technology, tight schedules, poor process, etc.
Resolve risks (evaluate if money could be lost by continuing system development
3. Spiral Quadrant: Develop next-level product:
Typical activites:
Create a design
Review design
Develop code
Inspect code
Test product
4. Spiral Quadrant: Plan next phase:
Prepared by: N.P.BHUSAL 10 Email ID: smcnpbhusl@gmail.com
PROGRAMMING LOGIC AND TECHNIQUES
Typical activities:
Develop project plan
Develop configuration management plan
Develop a test plan
Develop an installation plan
V-Model:
The V-model represents a software development process. It is also applicable to hardware development. It may be
considered an extension of the waterfall model. Instead of moving down in a linear way, the process steps are bent
upwards after the coding phase, to form the typical V shape. The V-Model demonstrates the relationships between
each phase of the development life cycle and its associated phase of testing.
When to use the V-Shaped Model:
• Excellent choice for systems requiring high reliability – hospital patient control applications
• All requirements are known up-front
• When it can be modified to handle changing requirements beyond analysis phase
• Solution and technology are known.
Advantages
Each phase has specific deliverables.
Higher chance of success over the waterfall model due to the development of test plans early on during the life
cycle.
Works well for small projects where requirements are easily understood.
Disadvantages
• Little flexibility and adjusting scope is difficult and expensive.
• Software is developed during the implementation phase, so no early prototypes of the software are produced.
• Does not handle iterations or phases
• Does not easily handle dynamic changes in requirements.
• Does not contain risk analysis activities.
Evolutionary Model:
In 1988, Boehm defines the evolutionary process model as a model whose stages consists of expanding increments
of an operational software product. It has been observed that the software engineer should accept the fact that
failures in the first version of an application inevitably lead to the need for redoing. It is also called incremental
approaches of the software development. This type of model consists of stepwise development, in which parts of
some stages are postponed in order to produce some useful set of functions earlier in the development of the project.
Multiple development cycles take place here, making the life cycle a “multi-waterfall” cycle. Cycles are divided up
into smaller, more easily managed iterations. Each iteration passes through the requirements, design,
implementation and testing phases. A working version of software is produced during the first iteration, so you have
working software early on during the software life cycle. Subsequent iterations build on the initial software
produced during the first iteration.
Advantages:
• Generates working software quickly and early during the software life cycle.
• More flexible – less costly to change scope and requirements.
• Easier to test and debug during a smaller iteration.
Customers can “see” the system requirements as they are being gathered
Developers learn from customers
A more accurate end product
Unexpected requirements accommodated
Allows for flexible design and development
Steady, visible signs of progress produced
Interaction with the prototype stimulates awareness of additional needed functionality
Disadvantages
• Each phase of an iteration is rigid and do not overlap each other.
• Problems may arise pertaining to system architecture because not all requirements are gathered up front for the
entire software life cycle.
RAD model:
RAD Stands for Rapid Application Development. It is an incremental software development process model that
emphasizes an extremely short development cycle. The RAD model is a “high speed “adaptation of linear sequential
model in which development is achieved by using component-based construction. The RAD model is a high-speed
adaptation of the linear sequential model / Waterfall model.
When to use RAD:
• Reasonably well-known requirements
• User involved throughout the life cycle
• Project can be time-boxed
• Functionality delivered in increments
• High performance not required
• Low technical risks
• System can be modularized