Sie sind auf Seite 1von 23

General OOP concepts

The beginning
Low Level Languages(LLL) Machine Languages, need to know circuitry to write code in LLL, written in binary code, very difficult, cumbersome.

High Level Languages Offer English words, follow constructs for sequence, selection, decision, iteration thro loops. HLL get converted into machine language using compilers/interpreters

Programming Practices
Procedural Programming Emphasis is on doing things, data is not taken care of, involves passing arguments to functions, returning values from functions. Many instructions are written to carry out a task. These instructions are grouped together to from functions. In order to develop a logical program you concentrate on these functions.
4

Least concentration is on the data. Hence important data items are defined globally thus accessible to those functions who do not need them. Hence changing a data item may affect one or more functions in turn affecting the normal sequencing of the program.

Characteristics of POP
Emphasis is on functions (logical steps) Functions share global data Data values keep floating from one functions to another Use top down approach of programming

Modular Programming As size increases writing code becomes difficult, hence program is broken down into small modules (functions). Again, data arrangement cant be changed without change in all functions that access the data

OOP Is an approach to standardize the programs by creating partitioned memory area for both data and function. Does not allow data to move freely from function to function. The complete problem is decomposed into smaller entities called objects. The data is used in such a way that is cannot be changed or edited from other functions or objects. The data of an object can be accessed only by the functions associated by that object.

Features of OOP
Gives stress to data items than functions It makes the problem simpler by dividing it into number of objects Easily modify data without change in the function

Basic elements of OOP


Objects Classes Encapsulation Abstraction Modularity Inheritance Polymorphism
10

Objects
Break down of problem into small components called objects Basic elements of OOP, also called as entities Set of related objects may exchange data & information and interact with each other

11

Creation of Object:

Employee obj = new Employee( );


12

Object Is a unique entity which contains data and functions (characteristics and behaviour)

In a payroll system, object may be an Employee where characteristics are name, designation, basic pay and behaviour as calculating gross pray, provident fund, printing pay slip etc.
13

Classes
Objects contain states and behaviour. The behaviour (method) is used to manipulate the state (data). It is user defined data type. Any variable declared of that type is considered an object of that class.

14

Class is a set of different objects. Each object of a class possesses same attributes and behaviour within the same class. As an object is a product of the class, hence class is also referred to as object factory.

15

Modularity
Breaking down the program into small modules. In large applications where number of classes have to be used the use of modules helps cope with complexity of the program. In java modularity is implemented thro packages These packages can be invoked using the import statement.

16

4 Pillars of OOP
Encapsulation Abstraction Polymorphism Inheritance

17

Encapsulation
In OOP data cannot move freely from function to function. They are kept in the corresponding class in such a way that they will not be accessible to the outside world except by using them thro the related functions. Such insulation of data, which cannot be accessed directly outside the class premises although they are available in the same program is known as Data Hiding. System of wrapping data and function into a single unit (class) is called as Encapsulation
18

Abstraction
Refers to the act of representing essential features without including background details The class encapsulates the data items and the functions to promote abstraction. The data members are accessed only thro the related function.

19

Polymorphism
Poly many Morphs forms Function can be used for many purposes. A function can be used to handle different number and different types of arguments. Function overloading is an example of Polymorphism.
20

Inheritance
Property by which objects of one class can link and share properties of objects from another class. Properties of the base class are derived by the derived class

21

Vehicle (modes of transport)

Base class

Automobiles

drawn

car

bus

Bullock cart

Horse drawn

Derived class

22

Access Specifiers
private members of the class can be used only in that class. public can be used in all classes in the same package as well as different packages. default members of the class can be used in the same package. (If no access specifier is given then it is default.In book - wrong). protected members of the base class can be used in the same class as well as the derived class. 23

Das könnte Ihnen auch gefallen