BASIC CONCEPTS OF OBJECT-ORIENTED PROGRAMMING
The general concepts of OOP which form the heart of Java language.
Object and Classes:
Objects are the basic runtime entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program may handle. They may also represent user-defined data types such as vectors and lists. Any programming problem is analyzed in terms of objects and the nature of communication between them. When a program is executed, the objects interact by sending messages to one another. Each object contains data and code to manipulate the data. Objects can interact without having to know the details of each other’s data or code.
The objects contain data and code to manipulate that data. The entire set of data and code of an object can be made a user-defined data type using the concept of a class. A class may be thought of as a ‘data type’ and an object as a ‘variable’ of that data type. Once a class has been defined, we can create any number of objects belonging to that class. Each object is associated with the data of type class with which they are created. A class is thus a collection of objects of similar type. For example, mango, apple, and orange are members of the class fruit.
Data Abstraction and Encapsulation:
The wrapping up of data and methods into a single unit(called class) is known as encapsulation. Data encapsulation is the most striking feature of a class. The date is not accessible to the outside world and only those methods, which are wrapped in the class, can access it. These methods provide the interface between the object’s data and the program. This insulation of the data from direct access by the program is called data hiding.
Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight and cost, and methods that operate on these attributes. They encapsulate all the essential properties of the objects that are to be created.
Inheritance:
Inheritance is the process by which objects of one class acquire the properties of objects of another class. Inheritance is supports the concept of hierarchical classification. For example, the bird robin is a part of the class flying bird, which is again a part of the class bird.
In OOP, the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have the combined features of both the classes.
Polymorphism:
Polymorphism is another important OOP concept. Polymorphism means the ability to take more than on form. For example, an operation may exhibit different behavior in different instances. The behavior depends upon the types of data used in the operation. For example, below figure illustrates that a single function name can be used to handle different number and different number and different types of arguments. This is something similar to a particular word having several different meanings depending on the context. Polymorphism is extensively used in implementing inheritance.
Dynamic Binding:
Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at runtime. It is associated with polymorphism and inheritance. A procedure call associated with a polymorphic reference depends on the dynamic type of that reference.
Message Communication:
An object oriented program consists of a set of objects that communicate with each other. The process of programming in an object-oriented language, therefore, involves the following basic steps:
1. Creating classes that define objects and their behaviour.
2. Creating objects from class definitions.
3. Establishing communication among objects.
Objects communicate with one another by sending and receiving information much the same way as people pass message to one another as shown in below figure. The concept of message passing makes it easier to talk about building systems that directly model or simulate their real-world counterparts.
A message for an object is a requesting for execution of a procedure, and therefore will invoke a method (procedure) in the receiving object that generates the desired result Objects have a life cycle. They can be created and destroyed. Communication with an object is feasible as long as it is alive.
Benefits of OOP:
OOP offers several benefits to both the programmer designer and the user. Object orientation contributes to the solution of many problems associated with the development and quality of software products. The principal advantages are:
Through inheritance, we can eliminate redundant code and extend the use of existing classes.
We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity.
The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.
It is possible to have multiple objects to coexist without any interference.
It is possible to map objects in the problem domain to those objects in the program.
The data-centered design approach enables us to capture more details of a model in an implementable form.
Object-oriented systems can be easily upgraded from small to large systems.
Message passing techniques for communication between objects make the interface description with external systems much simpler.
Software complexity can be easily managed.
Applications of OOP :
The most popular application of object-oriented programming, up to now, has been in the area of user interface design such as windows. There are hundreds of windowing systems developed using OOP techniques.
Real business systems are often much more complex and contain many more objects with complicated attributes and methods. OOP is useful in this type of applications because it can simplify a complex problem. The promising areas for application of OOP includes:
· Rea-time systems
· Simulation and modeling
· Object-oriented databases
· Hypertext, hypermedia and expertext
· AI and expert systems
· Neural networks and parallel programming
· Decision support and office automation systems
· CIM/CAD/CAD system
It is believed that the richness of OOP environment will enable the software industry to improve not only the quality of software systems but also its productivity. Object-oriented technology is certainly going to change the way software engineers will think, analysis design and implement systems in the future.