Object oriented programming Concepts Naresh Proddaturi 09/10/2012 Naresh Proddaturi 1
Problems with Procedural language Data is accessible to all functions It views a program as a series of steps to be carried out 09/10/2012 Naresh Proddaturi 2
OOP offers OOP is a way of organizing programs. OOP programs are organized around objects, which contain both data and functions that act on that data. 09/10/2012 Naresh Proddaturi 3
Object and Encapsulation The fundamental idea behind object-oriented languages is to combine both data and the functions that operate on that data into a single unit called an object. You can t access the data directly. The data is hidden, so it is safe from accidental alteration. Data and its functions are said to be encapsulated into a single entity. (encapsulation). No other functions can access the data. Calling an object s member function is referred to as sending a message to the object. 09/10/2012 Naresh Proddaturi 4
Characteristics of Object- Oriented Languages Objects: in an object-oriented language problem will be divided into objects. These relate to objects in real world. Class:A class is thus a description of a number of similar objects. A class serves as a plan, or blueprint. It specifies what data and what methods will be included in objects of that class. An object is often called an instance of a class. 09/10/2012 Naresh Proddaturi 5
A class and its objects Class is a template Object is a example of a class 09/10/2012 Naresh Proddaturi 6
Inheritance Inheritance allows a class to be derived from an existing class without modifying it. The derived class has all the data and functions of the parent class, but adds new ones of its own. 09/10/2012 Naresh Proddaturi 7
Reusability Reusability: Once a class has been written, created, and debugged, it can be distributed to other programmers for use in their own programs. This is called reusability. In OOPS an existing class can be used without modifying it and add additional features and capabilities to it.this is done by deriving a new class from the existing one. The new class will inherit the capabilities of the old one, but is free to add new features of its own. Reusability is using a class over and over in different programs. The ease with which existing software can be reused is an important benefit of OOP. 09/10/2012 Naresh Proddaturi 8
Polymorphism and Overloading Using operators or functions in different ways, depending on what they are operating on, is called polymorphism (one thing with several distinct forms). When an existing operator, such as + or =, is given the capability to operate on a new data type, it is said to be overloaded. Overloading is a kind of polymorphism. 09/10/2012 Naresh Proddaturi 9
Encapsulation, Discrete, Abstract classes & Data Abstraction Declaring member variables as private or protected is known as encapsulation or data hiding objects are discrete entities and that we communicate with them by calling their member functions Some classes are designed specifically to be inherited by other sub classes and objects of such classes cannot be directly instantiated. These classes are called Abstract Classes. Data Abstraction is hiding of implementation details so that classes are protected from unintentional user errors. 09/10/2012 Naresh Proddaturi 10
Interface An interface allows us to define the behaviours of a class without having to worry about how it will be achieved 09/10/2012 Naresh Proddaturi 11
Modularity Modularity is a software engineering approach where a programmed solution consists of a number of self-contained-but connected-parcels of code called modules. 09/10/2012 Naresh Proddaturi 12
message passing A member function call is one implementation of passing a message. Message passing is a different way of handling the need in OO code for one object to get another object (or potentially itself) to do something. When objects need to interact with each other, they pass information to one another. This interaction is known as message passing. 09/10/2012 Naresh Proddaturi 13
Identifying methods and properties Class Identify the Actions Identify the Attributes Examples Dog 09/10/2012 Naresh Proddaturi 14
OOP: Dog Methods (actions) Wag tail Bark Poo run Properties (Attributes ) Breed age 09/10/2012 Naresh Proddaturi 15
TASK Identify Methods and Properties of a class Animal Car Person Boiler 09/10/2012 Naresh Proddaturi 16
References Java Complete reference-herbert Schildt www.java.com http://docs.oracle.com/javase/tutorial/index.html http://netbeans.org/ 09/10/2012 Naresh Proddaturi 17