Monday, August 27, 2018

Programming Techniques Object Oriented Programming in C

Programming Techniques Object Oriented Programming in C


Class 02 - Programming Techniques
(Object Oriented Programming)

 

A Survey of Programming Techniques



This chapter is a short survey of programming techniques. We use a simple example to illustrate the particular properties and to point out their main ideas and problems.



Roughly speaking, we can distinguish the following learning curve of someone who learns program:



  • Unstructured Programming
  • Procedural Programming
  • Modular programming
  • Object Oriented Programming

Unstructured Programming



Usually, people start learning programming by writing small and simple programs consisting only of one main program. Here �main program" stands for a sequence of commands or statements which modify data which is global throughout the whole program. We can illustrate this as shown in Fig. 1.1
 


Figure 2.1:

Unstructured programming - The main program directly operates on global data.



As you should all know this programming technique provide tremendous disadvantages once the program gets sufficiently large. For example, if the same statement sequence is needed at different locations within the program, the sequence must be copied. This has lead to the idea to extract these sequences, name them and offering a technique to call and return from these procedures.



Procedural Programming


With procedural programming you are able to combine returning sequences of statements into one single place. A procedure call is used to invoke the procedure. After the sequence is processed, flow of control proceeds right after the position where the call was made (Fig. 1.2).


 
Figure 1.2

Execution of procedures - After processing flow of controls proceeds where the call was made.


With introducing parameters as well as procedures of procedures (sub procedures) programs can now be written more structured and error free. For example, if a procedure is correct, every time it is used it produces correct results. Consequently, in cases of errors you can narrow your search to those laces which are not proven to be correct.



Now a program can be viewed as a sequence of procedure calls. The main program is responsible to pass data to the individual calls, the data is processed y the procedures and, once the program has finished, the resulting data is resented. Thus, the flow of data can be illustrated as a hierarchical graph, a tree, as shown in Fig. 1.3 for a program with no sub procedures.
Figure 1.3
Procedural programming - The main program coordinates calls to procedures and hands over appropriate data as parameters.

To sum up: Now we have a single program which is divided into small pieces called procedures. To enable usage of general procedures or groups of procedures also in other programs, they must be separately available. For that reason, modular programming allows grouping of procedures into modules.


Structured or Modular programming

It was introduced in 1960s. It has very best advantage to write very large programs. In this programming approach a large program is broken down into smaller units. In C and C++ these smaller units are called functions. In other programming languages, the same concept may be referred to as subroutines, or sub-programs, or proceduresor modules.

With modular programming procedures of a common functionality are grouped together into separate modules. A program therefore no longer consists of only one single part. It is now divided into several smaller parts which interact through procedure calls and which form the whole program (Fig. 1.4).


Figure 1.4
Modular programming - The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters.

Each module can have its own data. This allows each module to manage an internal state which is modified by calls to procedures of this module. However, there is only one state per module and each module exists at most once in the whole program.

In the structured or modular programming, the logic of the program can be expressed using three control structures, where each structure has single entry point and a single exit point. These control structures are:

  • Sequential Structure
  • Conditional or Selection Structure
  • Iterative or Repetitive or Loop Structure
OBJECT-ORIENTED PROGRAMMING

The object oriented programming concept was introduced in the late1960s. But now it has become the most popular approach to develop software. In object oriented programming, a program in designed by using objects. We can say that the whole program is divided into set of objects. It is an easy and very flexible approach for designing and organizing the program. Most popular and commonly used object-oriented programming languages are C++ and JAVA.

An object is a component of program that has set of functions and data structures. Every object has some properties that s called its data members and some functions that is called member functions.

The object-oriented approach is based upon the concepts of data abstraction and information hiding. The abstraction is a tool that allows a programmer to consider a component of software at conceptual level without knowing the detail of implementation of component into system. An abstractionof a component describes the external behavior of that component but does not describe internal details of the component that produced the behavior.

Object-oriented programming solves some of the problems just mentioned. In contrast to the other techniques, we now have a web of interacting objects, each house-keeping its own state (Fig. 1.5).
Figure 1.5
Object-oriented programming - Objects of the program interact by sending messages to each other.


go to link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.