Object- Oriented Programming – An Introduction
OOPs Stands for object oriented programming. It is a very efficient langauge which remove the problems regarding procedural programming and its based on real life.
The first achievement of OOP towards better design and maintenance is the removal of ambiguity, OOP handles is the problem of non-flexibility of code.
Objects are software bundles of data and related procedures.
visual representation of a software object:
Encapsulation
Encapsulation is beneficial
Encapsulation is very efficient function of OOPs which provides the essential information to user and hided information which ic not valid for a normal user. In encapsulation functions and variables get in to a software and gives a good output.
- Modularity
- Information hiding
Messages
Message passing is a very ncie function of OOPs. Through this function different modules of a software can interact with each other and communicate with eash other.
When a software needs interaction of other module then it can send message to it and can get response.
Messaging
A Message with Parameters
Three components comprise a message:
- The object to whom the message is addressed (bicycle)
- The name of the method to be performed (changing gears) any parameters needed by the method (to a higher gear)
Messages is OOPs are beneficial.
A object in OOPs can do work only by communicating with other moduleks and objects & functions, so message passing supports all possible interactions between objects.
Objects don't need to be in the same process or even on the same machine to send and receive messages back and forth to each other.
Class
A class is a blueprint or prototype that defines the variables and the methods common to all objects of a certain kind.
The Term "Object"
In the real world it’s obvious that classes are not themselves the objects that they describe.
Then also occurs because many people use the term “object” inconsistently and use it to refer to both classes and instances.
The main difference between a class and an object is that objects are tangible, but a class is always intangible. You can’t see a class but you can always see an object.
The Benefits of Classes
Objects provide the benefit of modularity and information hiding. Classes provide the benefit of reusability
What is Inheritance?
Classes inherit state and behavior from their superclass. Inheritance provides a very helpful concept of code reusability.
Hierarchy of Classes
The Benefits of Inheritance
Subclasses provide specialized behaviors from the basis of common elements provided by the superclass. Through the use of inheritance, programmers can reuse the code in the superclass many times.
Programmers can implement superclasses that define "generic" behaviors (called abstract classes). The essence of the superclass is defined and may be partially implemented but much of the class is left undefined and unimplemented. Other programmers fill in the details with specialized subclasses.
Abstraction
In java, classes are used to categorize data in order to model real life systems. Abstraction is this process of categorizing data.
apstraction
Polymorphism
Polymorphism may be defined as the ability of related objects to respond to the same message with different, but appropriate, actions.
Polymorphism
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 run-time.
It is associated with polymorphism and inheritance.
Overloading
In Object Oriented Programming if a method depending on some information does different job at different times that method is overloaded .Overloading is nothing but a kind of polymorphism.
Example:
Suppose drawGraph() is a mechanism to draw a graph depending on the information provided,
- DrawGraph(): Draws a point at any random location.
- DrawGraph(point1, point2): Draws a line from point1 to point2
- DrawGraph(point1,point2,point3,point4): Draw a rectangle using these points.
Overriding
Inheritance is a mechanism of inheriting the traits of parents but some times some properties should be modified according to the need like a son inherits legs from his parents but his walking style is different. This is Overriding.
It is again a kind of polymorphism and very important in terms of dynamic decisions.
Benefits of OOP
Through inheritance, we can eliminate redundant code and extend the use of existing classes.
We can build programs from the standard working modules, which 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 instances of an object to co-exist without any interference.
- It is possible to map objects in the problem domain to corresponding objects in the program.
- It is easy to partition the work in a project based on objects.
- The data-centered design approach enables us to capture more details of a model in implementable form.
- Object-oriented systems can be easily upgraded from small to large systems.
- Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler.
- Software complexity can be easily managed.