SE Note 1
SE Note 1
SE Note 1
Coding is done by the coder or programmers who are independent people than
the designer. The goal is not to reduce the effort and cost of the coding phase,
but to cut to the cost of a later stage. The cost of testing and maintenance can be
significantly reduced with efficient coding.
Goals of Coding
1. To translate the design of the system into a computer language
format: The coding is the process of transforming the design of a system
into a computer language format, which can be executed by a computer
and that perform tasks as specified by the design of operation during the
design phase.
2. To reduce the cost of later phases: The cost of testing and maintenance
can be significantly reduced with efficient coding.
3. Making the program more readable: Program should be easy to read and
understand. It increases code understanding, having readability and
understandability as a clear objective of the coding activity can itself help
in producing more maintainable software.
A coding standard lists several rules to be followed during coding, such as the
way variables are to be named, the way the code is to be laid out, error return
conventions, etc.
Coding Guidelines
General coding guidelines provide the programmer with a set of the best
methods which can be used to make programs more comfortable to read and
maintain. Most of the examples use the C language syntax, but the guidelines can
be tested in all languages.
2. Spacing: The appropriate use of spaces within a line of code can improve
readability.
Example:
Bad: cost=price+(price*sales_tax)
fprintf(stdout ,"The total cost is %5.2f\n",cost);
4. The length of any function should not exceed 10 source lines: A very lengthy
function is generally very difficult to understand as it possibly carries out many
various functions. For the same reason, lengthy functions are possible to have a
disproportionately larger number of bugs.
Structured Programming
In structured programming, we sub-divide the whole program into small modules
so that the program becomes easy to understand. The purpose of structured
programming is to linearize control flow through a computer program so that the
execution sequence follows the sequence in which the code is written. The
dynamic structure of the program then resembles the static structure of the
program. This enhances the readability, testability, and modifiability of the
program. This linear flow of control can be managed by restricting the set of
allowed applications construct to a single entry, single exit formats.
Code Block
Sequence
Alternation
Iteration
Nested Structures
Object-Oriented Design
In the object-oriented design method, the system is viewed as a collection of
objects (i.e., entities). The state is distributed among the objects, and each object
handles its state data. For example, in Library Automation Software, each library
representative may be a separate object with its data and functions to operate
on these data. The tasks defined for one purpose cannot refer to or change data
of other objects. Objects have their internal data which represent their state.
Similar objects create a class. In other words, each object is a member of some
class. Classes may inherit features from the superclass.
1. Objects: All entities involved in the solution design are known as objects.
For example, people, banks, companies, and users are considered as
objects. Every entity has some attributes associated with it and has some
methods to perform on the attributes.
2. Classes: A class is a generalized description of an object. An object is an
instance of a class. A class defines all the attributes which an object can
have and methods which represent the functionality of the object.
3. Messages: Objects communicate by passing messages. Messages consist
of the integrity of the target object, the name of the requested operation,
and any other action needed to perform the function. Messages are often
implemented as procedure or function calls.
4. Abstraction In object-oriented design, complexity is handled using
abstraction. Abstraction is the removal of the irrelevant and the
amplification of the essentials.
5. Encapsulation: Encapsulation is also called an information hiding concept.
The data and operations are linked to a single unit. Encapsulation not only
bundles essential information of an object together but also restricts
access to data and methods from the outside world.
6. Inheritance: OOD allows similar classes to stack up in a hierarchical manner
where the lower or sub-classes can import, implement, and re-use allowed
variables and functions from their immediate superclasses. This property
of OOD is called an inheritance. This makes it easier to define a specific
class and to create generalized classes from specific ones.
7. Polymorphism: OOD languages provide a mechanism where methods
performing similar tasks but vary in arguments, can be assigned the same
name. This is known as polymorphism, which allows a single interface to
perform functions for different types. Depending upon how the service is
invoked, the respective portion of the code gets executed.
From the above sequence chart, you can tell that we are exposing too
much information about building a house to the Buyer. The Buyer
must know what functions to call and the sequence of functions to
execute to be able to build a house. However, the Buyer should not
need to know how a house is built. Also, this makes it difficult to
accommodate any changes to the design decision of how a house is being
built because whenever you make a change to the design decision, you
must modify Buyer component as well. As such, information hiding
principle is not utilized.
From the sequence chart above, you can see that information regarding
how a house is built is hidden from the Buyer. The Buyer only needs to
know what materials it needs to pass into the Builder component to get
a house. If the builder is to change the way it builds the house, the
modification will only be done in the Builder component, and it will not
affect the Buyer component. As such, this structure uses the
Information Hiding principle.
Flexibility
Information Hiding principle provides flexibility to the programmer to
modify underlying design decisions made in a certain component. Since
the implementation details are hidden from the users of the component,
changes made will be localized to that component only. This also makes
debugging and maintaining the program easier.
Software Reuse
In most engineering disciplines, systems are designed by composing existing components that have been used
in other systems. Software engineering has been more focused on original development, but it is now recognized
that to achieve better software, more quickly and at lower cost, we need a design process that is based on
systematic software reuse. There has been a major switch to reuse-based development over the past 10 years.
System reuse: Complete systems, which may include several application programs.
Application reuse: An application may be reused either by incorporating it without change into
another or by developing application families.
Component reuse: Components of an application from sub-systems to single objects may be
reused.
Object and function reuse: Small-scale software components that implement a single well-
defined object or function may be reused.