0% found this document useful (0 votes)
89 views39 pages

Oops

1. Procedural programming focuses on algorithms and breaking programs into smaller functions, while object-oriented programming treats data as a critical element and organizes programs around real-world objects. 2. In object-oriented programming, classes define the data and behavior of objects, and inheritance allows classes to share and extend common properties. 3. Polymorphism and dynamic binding enable the same message to invoke different methods depending on an object's type at runtime.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views39 pages

Oops

1. Procedural programming focuses on algorithms and breaking programs into smaller functions, while object-oriented programming treats data as a critical element and organizes programs around real-world objects. 2. In object-oriented programming, classes define the data and behavior of objects, and inheritance allows classes to share and extend common properties. 3. Polymorphism and dynamic binding enable the same message to invoke different methods depending on an object's type at runtime.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 39

Object-Oriented Programming

Things we will learn in this lecture


A look at Procedure Oriented programming Object-Oriented programming Key Concepts in OO programming. Benefit of using OO paradigm. Brief history of C++. Miscellaneous

Procedural-Oriented programming
Conventional programming , using high level languages such as COBOL ,FORTRAN & C, is known as procedure-oriented programming (POP). A problem is viewed as a sequence of things to be done such as reading , calculating & printing. Using procedural paradigm, a problem is decomposed into several subproblems and subsubproblems. In POP number of functions are written to accomplish the tasks such as reading, calculating and printing.
3

Procedural programming paradigm

Fig. Typical structure of procedure-oriented program Structured top-down design: - First consideration: functions. - Secondary consideration: data structure.

characteristics of procedureoriented language.


Emphasis is on doing things (algorithms). Larger programs are divided into smaller programs known as functions. Most of the functions share global data. Data move openly around the system from function to function.

Problems of Procedural Paradigm


Data structure is neglected; Data tends to be generally spread across a system. Poor reusability and extensibility. High cost in maintenance. Real system has no top function. ... Software Crisis!

Characteristics of Contemporary Information Systems


The type and structure of data become a greater concern than the complexity of the processing. Software maintenance is more important since the specifications for the system change frequently. Applications are frequently on-line systems that respond interactively to users command. System decomposition should be based on how to represent a complex real world problem.
7

Object-Oriented Paradigm
The real world is made of interacting, classifiable and identifiable objects. To model the real world more closely Object-Oriented (OO) Paradigm.

Object-Oriented Paradigm
OOP treats data as a critical element in the program development. It ties data more closely to the functions that operate on it. It allows decomposition of a program into a number of entities called objects and then builds data & functions around these objects.
9

Fig. Organization of data and functions in OOP


10

11

Basic concepts of OO programming


Objects. Classes. Data abstraction and Encapsulation. Inheritance. Polymorphism. Dynamic binding. Message passing.
12

Abstract Data Type(ADT)


Real world objects have state (what it is) and behavior (what it does). To simulate real world objects in software system, we can use Abstract Data Type (ADT). An ADT is a type together with a set of operations on that type. An ADT defines the data(state) and Operation (behavior) of all objects belonging to a particular type. In C++, an ADT is modeled using class (and struct).

13

Class and Object


A class is a type. An object is an instance. All the objects of a certain class may have different data, but their behaviors are the same.

14

1)

Object :

i) Object are the basic run-time entities in an object-oriented system. ii) They may represent a person, a place a bank account, a table of data or any item that the program has to handle. iii) Programming problem is analyzed in terms of objects and the nature of communication between them. iv) Objects take up space in the memory & have an associated address like structure . v) When a program executes, the object interacts by sending messages to one another. Ex. If there are two objects customer and account then the customer object may send a message to account object requesting for the bank balance.

15

16

Objects

Fig. Two ways of representing an object

17

18

Classes

19

Data Abstraction & Encapsulation

20

Data Abstraction & Encapsulation


Abstraction is the representation of all the essential features of a real world object, including data(state) and operations(behavior). Encapsulation is the combination of data and operation into a software object. Information hiding is the division of an object into private and public parts. The public part provides the external interface. The private part(implementation details) is hidden inside the object.
21

Object = (private) data + (public) operations

22

Abstraction/ Encapsulation
Implementation details of the class are hidden. The access to the object is only through public methods. Methods: operations(functions) of a class.

23

Example: class Student { // class definition private: char id, name[20]; double balance, payrate; public: double TA_Salary() {/**/} void payFee(); }; //define method payFee of class Student void Student::payFee() {/* */} //create two Student objects Student student1, student2; salary1 = student1.TA_Salary(); //a message is sent to student1 student2.payFee(); //a message is sent to student2 Message: the name of a method.
24

Inheritance
One class can inherit data and methods from other more generic class. e.g. an apple is a kind of fruit; a graduate student is a kind of student. Goal:
To allow a class to be extended. To allow similar objects to share their common data and operations. To facilitates polymorphism and dynamic binding in C++.

A class inherits from more than one other classes multiple inheritance

25

26

Inheritance

Fig. Property inheritance

27

Polymorphism
Original meaning: Having many forms. Polymorphism is the ability to invoke different methods for the same message.

28

Polymorphism

Fig. Polymorphism
29

Dynamic Binding

30

Message Passing
Oops consists of a set of objects that communicate with each other. Message passing involves the following steps : 1. Creating classes that define objects & their behaviour, 2. Creating objects from class definitions, & 3. Establishing communication among objects. A message for an object is a request for execution of a procedure , & therefore will invoke a function ( procedure ) in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of the function (message) & the information to be sent. Example :

31

Benefits of OO Design
Increased productivity Enhanced reliability Improved maintenance Enhanced extensibility

32

Comparing Approaches

33

34

Introduction to C++
Developed by Bjarne Stroustrup in 1983 at the AT&T Bell lab. Derived primarily from two other languages: C and Simula67. It is a superset of C. C++ is a hybrid language since it supports both procedural and OO paradigm. C++ programs : Built from pieces called classes and functions C++ standard library : Rich collections of existing classes and functions

35

Extensions and file types.


Extension (s)
.h, .hxx, .hpp

File type
Interface descriptions (header or include files) Implementation files of C Implementation files of C++ Interface description (template)

.c .cc, .C, .cxx, .cpp, .c++ .tpl

36

Compilation steps.
.cc

Compiler

.h, .tpl

.o Linker

libraries

a.out
37

39

You might also like