You are on page 1of 22

Introduction to Object Oriented Programming concept

TEXT BOOKS
B. Trivedi, Programming with ANSI C++, Oxford University Press, 2010. Ira Pohl, Object Oriented Programming using C++, Pearson Education, Second Edition Reprint 2004.

REFERENCES
P.J.Deitel, H.M.Deitel, C++ How to Program, 7th edition, PHI, 2010 Balaguruswamy. E, Object Oriented Programming with C++, Fourth Edition, TMH, 2008. S. B. Lippman, Josee Lajoie, Barbara E. Moo, C++ Primer, Fourth Edition, Pearson Education, 2005. B. Stroustrup, The C++ Programming language, Third edition, Pearson Education, 2004.

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.

Drawbacks
This programming technique can only be used in a very small program. For example, if the same statement sequence is needed at different locations within the program, the sequence must be copied. If an error needed to be modified, every copy needs to be modified. This has lead to the idea to extract these sequences (procedure), name them and offering a technique to call and return from these procedures.

Procedural Programming
With procedural programming, you are able to combine sequences of calling 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 .

Procedures
With parameters and sub-procedures (procedures of 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 places which are not proven to be correct.

Procedure Program view


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 by the procedures and the resulting data is presented. Thus, the flow of data can be illustrated as a hierarchical graph, a tree.

Procedure Program view

Limitations of C Problem 1
Does not work when the program goes larger Losing the global view (abstract view) What is Abstraction? Save button in MS word Controls used VB or VC++ Real world examples Applying Brake in car Acceleration used in car

Limitations of C Problem 2
Idea of reuse is? missing Need many blocks in building a large program Large payroll program Management of employee system payroll HR management system personal info Both are not same however need to be consistent

Object oriented Programming


Adding new features to C to suit large programs Outcome of the research is object based or object oriented programming Programming is the process of solving real world problems Account program solves account related problems in real world Marksheet program solves calculating marks of individual students

Contd
C++ is extended from C, it is superset of C Is C++ not fully object oriented language? Is Smalltalk purely object oriented language? Most object oriented programming languages slower the execution of the program Advantage of C is its efficiency

Real world classes and objects


Real world consists of classes and objects All of us are objects of type humankind Delhi is an object is a class of city Amazon is an object of river

Examples for class and object

OOP concepts objects and class


Class is the extension of structure in C Structure contains attributes of the student Class contains attributes as well as actions on and by the student In C, functions are not part of the structure, they are independent StudentPrint(Lara), StudentPrint(Mathew) In C++, function is part of the class Objects of class can only operate over the functions owned by them This is the basic fundamental difference between C and C++

Real time scenario Rollcall program


Rollcall process Calling each students roll number or name and making an entry in the register Entities involved in Rollcall Teacher real world Subject real world Student real world Rollcall non real world

Entities of the system

Methods and Messages

Abstraction and Encapsulation


Abstraction hides unnecessary things and reveals only the necessary things Users can be saved from the complexity of relevant things Two kinds of attributes (data and function) Prerequisite for abstraction two different types of attributes (public and private) It is made that certain attributes are hidden and others are visible

Contd
What is encapsulation? Process of defining a class with some attributes hidden and some exposed is called encapsulation. Insulates object from the outside and provide access by only through the public interfaces

You might also like