Object Oriented Programming(OOPs) :features or characteristics of OOPs, advantages, disadvantages and Applications of OOPs.
Object-oriented programming (OOPs) :
OOPs refers to languages that uses objects in programming.
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects".
Objects contains both states and behaviours. (and identity also).
Features or Charecteristics of OOPs:
1.Classes
2.Objects
3.Encapsulation
4.Data Abstraction
5.Inheritance
6.Polymorphism
7.Dynamic binding
There are four pillars of OOPs :
1. Inheritance
2. Polymorphism
3. Abstraction
4. Encapsulation
1. classes :
Class represents a real world entity which acts as a blueprint for all the objects.
Class is "blue print" or "template"
for creating all the objects.
We can create as many objects as we need using Class.
Example:
We create a class for “ Student ” entity as below
Class Student
{
String id;
int age;
String course;
void result()
{
System.out.println(“Student enrolled”);
}
}
Above definition of class contains 3 fields id,age and course and also it contains behavior or a method called “ result ”.
2. Object:
Object is an instances of class.
Objects are real world entity which may represents person,place,animalsor any other things.
It contains both variables (used for holding the data) and methods(used for defining the behaviors).
Syntax :
Student s1 = new Student();
We can create any number of objects using this class and all those objects will get the same fields and behavior.
Objects have three characteristics:
1.Identity:it is used internally by the JVM to identify each object uniquely.
2.States:it represents the data of an object.
it can be represented as instance variables(fields) of the class.
3.Behavior: it represents the functionality
of an object.
It can be represented as methods of the class.
Examples of states and behaviors:
Example 1:
Object :Student
State :color, name,age, height,weight
Behavior:dancing, singing , eating, writing, drinking etc.
Example 2:
Object: House
State: Address, Color, Area
Behavior: Open door, close door.
3.Encapsulation :
Encapsulation is the process of binding object state(fields) and behaviors(methods) together in a single entity called “Class”.
Binding (or wrapping) code and data together into a single unit are known as encapsulation.
Java class is the example of encapsulation.
Java bean is the fully encapsulated class because all the data members are private here.
4.Abstraction :
Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user.
Hiding internal details and showing functionality is known as abstraction.
Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation or explanation.
For example phone call, we don't know the internal processing.
We can achieve abstraction in Java using 2 ways:
1. Abstract class
2. Interface
Data hiding :
The insulation of data from direct access
Or accidental access is called data hiding(information hiding).
it is the process of hiding the
Details of an object from another object.
Data hiding is the process by which access modifiers are used to hide the visibility of java methods and variables.
-Helps to secure & protect the data.
-Data Hiding is not possible without Encapsulation.
Example :ATM machine.
We know the withdrawal of money. But we don't know the implementation of that software. Actually how it works.
The user will have no idea about the inner implementation of the machine. It will not be visible to the user that how the machine is storing values in the variables. User only know the functionality of that machine.
5.Inheritance :
One class inherits or acquires the properties of another class is called inheritance.
Inheritance is a process of defining a new class based on an existing class by extending its common data members and methods.
-->It allows us to reuse of code. Inheritance provides the idea of reusability of code .
-->It is used to achieve runtime polymorphism.
The parent class is called the base class or super class. The child class that extends the base class is called the derived class or sub class or child class.
To inherit a class we use extends keyword. Here class A is child class and class B is parent class.
Syntax :
class A extends B
{
}
Types Of Inheritance:
Single Inheritance: it is the process of deriving new class from only one base class.
For example class A extends class B.
Multilevel inheritance: it is the process of deriving new class from already derived from another base class.
For example class A extends class B and class B extends class C.
Hierarchical inheritance: it is the process of deriving multiple classes from only one base class.
For example, class B extends class A and class C extends class A.
Multiple inheritance : it is the process of deriving new class from multiple base classes.
java does not supports multiple inheritance directly.
To achieve multiple inheritance in Java we use new concept that is called interface.
6. Polymorphism :
Polymorphism means ability of an object to take more than one form.
Or
It means one name multiple forms.
In java, we can achieve it using method overloading and method overriding.
For example: to convince the customer differently, to draw something, for example: shape
The Shape class and all the classes that are inherited from it, such as:
Rectangle
Triangle
Circle
polymorphism is mainly divided into two types:
Compile time polymorphism: This type of polymorphism is achieved by function overloading or operator overloading.
operator overloading concept is not supported in Java.
Runtime Polymorphism : This type of polymorphism is achieved by Function Overriding.
7.Dynamic binding :
If linking(association) between method call and method implementation(body) resolved at runtime time by jvm is known as dynamic or late binding.
Example :method overriding
-Compiler deos not decided which method to call. It will decided by JVM.
Dynamic method dispatch is a mechanism by which a call to an overridden method is resolved at runtime rather than compile time.
Advantages of OOPs :
1.reusability
2.simplicity(easy to understand).
3.extensibility
4. data redundancy
5 . data security and protection (hiding &encapsulation ).
6 . Faster development.
7 . Easy to modifiability & maintainability
Disadvantage of OOPs:
1.Compiler overhead.
2. runtime overhead.
3.cost of dynamic method dispatch(dynamic binding).
4. requires knowledge of programming & software methodology.
Applications of OOPs :
1 . real time systems
2.simulation and modelling.
3. object oriented databases
4 . hypertext, hypermedia and expertext.
5.AI and expert systems
6.Nueral system and parallel programming
7.CAM/CAD systems
8 . decision support and office automation systems.
Comments
Post a Comment