Sie sind auf Seite 1von 28

Object Oriented Programming

What is programming?
Programming is taking A problem Find the area of a rectangle A set of data length width A set of functions area = length * width Then, Applying functions to data to solve the problem
2

The Evolution of Programming Languages


To build programs, people use languages that are similar to human language. The results are translated into machine code, which computers understand. Programming languages fall into three broad categories: Machine languages Assembly languages Higher-level languages

The Evolution of Programming Languages Machine Languages


Machine languages (first-generation languages) are the most basic type of computer languages, consisting of strings of numbers the computer's hardware can use.

The Evolution of Programming Languages Assembly Languages


Assembly languages (second-generation languages) are only somewhat easier to work with than machine languages. To create programs in assembly language, developers use cryptic English-like phrases to represent strings of numbers. The code is then translated into object code, using a translator called an assembler.

Assembly code

Assembler Object code

The Evolution of Programming Languages Higher-Level Languages


Higher-level languages are more powerful than assembly language and allow the programmer to work in a more English-like environment.

Higher-Level Languages Third-Generation Languages


Third-generation languages (3GLs) are the first to use true English-like phrasing, making them easier to use than previous languages. 3GLs are portable, meaning the object code created for one type of system can be translated for use on a different type of system. The following languages are 3GLs: FORTAN COBOL BASIC Pascal C C++ Java ActiveX

Procedure Oriented Language


Procedure Oriented programming basically consist of writing a list of instructions for the computer to follow , and organize these instructions into groups is known as functions. The problem is viewed as a sequence of things to be done such as reading, calculating, and printing. A number of functions are written to accomplish these tasks. The primary focus is on functions. Procedures, also known as routines, subroutines, methods, or functions.

Procedural Programming

The main program coordinates calls to procedures and hands over appropriate data as parameters.
10

Procedure Oriented Language


Characteristics: 1. Emphasis is on doing things(algorithms).
2.Large programs are divided into smaller programs called functions. 3.Most of functions share global data. 4. Data move openly from function to function. 5. Functions transforms data from one form to another. 6. Top to down approach.

Disadvantages
y Unrestricted Access y Data is exposed to whole program, so no security for data. y Difficult to relate with real world objects. Separate data y y y y y
and functions. Importance is given to the operation on data rather than the data. Increases complexity when program becomes large. A change in global data may necessitate rewriting all the functions that access that item. Doesn t emphasize on what to do to solve a problem. Difficult to modify.

Object Oriented Programming

OOPs treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data with the function that operate on it and protects it from accidental modification from outside functions. OOPs allows decomposition of data into number of entities called objects, and then builds data and function around it. The data of object can be accessed only by the functions associated with that object.

Object-Oriented Concept

Objects of the program interact by sending messages to each other


14

Striking Features of OOPs


Emphasis is on data rather than functions. Programs are divided what we are known as objects. Functions that operate on the data of an object are tied together in a data structure. Data is hidden and can not be accessed by external functions. Objects may communicate through functions. New functions and data can be easily

Organization of functions and data


Object A Data Functions Object C Data Functions Object B Data Functions

Definition of OOPs
Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them. Object-oriented programming (OOP) is a programming paradigm that uses "objects" data structures consisting of datafields and methods together with their interactions to design applications and computer programs.

So, what are objects?


an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain. Or An "object" is anything to which a concept applies. Etc.

Object
Objects are run time entities in object oriented system. They may represent a person, a place, a bank account that program has to handle. Programs objects should be chosen such that they match closely with real world objects.

What is an object?
Tangible Things Roles Incidents Interactions Specifications as a car, printer, ... as employee, boss, ... as flight, overflow, ... as contract, sale, ... as colour, shape,

Representing an Object

Class
Class is a collection of objects of similar type. Classes are user defined data types and behave like built in type of programming language. Eg:- Mango, apple ,orange are the members of same class fruit.

Classification
Animal Mammal Reptile

Rodent

Primate

Cats

Mouse

Squirel

Rabbit

Features of Object oriented Programming

The important features of Object Oriented programming are:

Inheritance Polymorphism Data Hiding Encapsulation Data Abstraction

DATA ABSTRACTION It refers to the act of representing essential features without including the background details or explanations. ENCAPSULATION The wrapping up of data and functions into a single unit (called class) is known as encapsulation. DATA HIDING The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. This insulation of data from access by the program is called data hiding INHERITANCE It is the process by which objects of one class acquire the properties of objects of another class. i.e. deriving a new class from the existing one. POLYMORPHISUM Polymorphism means having many forms . It allows different objects to respond to the same message in different ways, the response specific to the type of the object.

MESSAGE PASSING: An object oriented program consists of a set of objects that communicate with each other with messages. A message for an object is a request for execution of a procedure and will invoke a function in the object that generates the desired result. It involves: specifying - the name of object, - the name of function(message) and - information to be sent.

Difference Between Procedure Oriented and OOP


. Main program is divided into small parts depending on the functions. 2. The Different part of the program connects with each other by parameter passing & using operating system. 3. Every function contains different data. 4. Functions get more importance than data in program. 5. Most of the functions use global data. 6. Same data may be transfer from one function to another 7. There is no perfect way for data hiding. 8. Functions communicate with other functions maintaining as usual rules. 9. More data or functions can not be added with program if necessary. For this purpose full program need to be change. 10. To add new data in program user should be ensure that function allows it. 11. Top down process is followed for program design. 12. Example: Pascal, Fortran 1. Main program is divided into small object depending on the problem. 2. Functions of object linked with object using message passing. 3. Data & functions of each individual object act like a single unit. 4. Data gets more importance than functions in program. 5. Each object controls its own data. 6. Data does not possible transfer from one object to another. 7. Data hiding possible in OOP which prevent illegal access of function from outside of it. 8. One object link with other using the message passing. 9. More data or functions can be added with program if necessary. 10. Message passing ensure the permission of accessing member of an object from other object. 11. Bottom up process is followed for program design. 12. Example: C++, Java.

Das könnte Ihnen auch gefallen