OBJECT-ORIENTED
PROGRAMMING
LECTURE1
How do we Develop Applications?
Object-Oriented Programming is a strategy that provides some
principles for developing applications or developing software.
Methodologies Develop Applications:
Object-Oriented Programming.
Structured Programming.
Procedural Programming.
Modular Programming.
With the help of Object Orientation, the application development or the
programming becomes more and more systematic and we can follow
the procedures of engineering
Object-Oriented vs Structured
Programming
Structured Programming Object-Oriented Programming
It relies on concept of objects that contain
It is a subset of procedural programming
data and code.
Programs are divided into small programs Programs are divided into objects or
or functions. entities
It provides less flexibility and abstraction It provides more flexibility and abstraction
It gives more importance of code. It gives more importance to data.
It generally follows “Top-Down Approach It generally follows “Bottom-Up Approach”
Why Object Orientation?
OOP language allows to break the program into the bit-sized problems
that can be solved easily (one object at a time).
The new technology promises greater programmer productivity, better
quality of software and lesser maintenance cost.
OOP systems can be easily upgraded from small to large systems
OOPs provide some principles and using those principles we can
overcome Modular Programming Problems.
What is Object-Oriented
Programming?
Object-Oriented Programming (OOPs) in java is a design
approach where we think in terms of real-world objects rather
than functions or methods.
Object-Oriented Programming
Reusability:
To address reusability, object-oriented programming provides something
called Classes and Objects. So, rather than copy-pasting the same code
again and again in different places.
Extensibility:
Suppose you have a function and you want to extend In OOPs, this
problem is addressed by using some concepts called Inheritance,
Aggregation, and Composition.
Object-Oriented Programming
Simplicity:
In OOPs, this problem is addressed by using some concepts called
Abstraction, Encapsulation, and Polymorphism.
Maintainability:
As OOPs address Reusability, Extensibility, and Simplicity, we have good
maintainable code and clean code which increases the maintainability of
the application.
Object-Oriented Programming
What are the OOPs Principles or OOPs Concepts
in java?
OOPs, provide 4 principles. They are
I. Encapsulation
II. Inheritance
III. Polymorphism
IV. Abstraction
Note: Don’t consider Class and Objects as OOPs principle. We use class
and objects to implement OOPs Principles.
Object-Oriented Programming
Abstraction is the process of representing the essential
features without including the background details.
Encapsulation is the process of binding the data and
functions together into a single unit (i.e. class) .
Abstraction and Encapsulation are related to each other. We can say that Abstraction is
logical thinking whereas Encapsulation is its physical implementation.
Object-Oriented Programming
Inheritance is the process by which the members of one class
are transferred to another class.
Polymorphism means the ability to take more than one form.
Object-Oriented Programming
Class and Objects from Layman’s Point of View.
Everything that you can see and touch in the world is an object
and there is a class for it.
classification is based on the criteria that we are adopting.
Design is nothing but the blueprint
Object-Oriented Programming
Class and Objects from Programming Language Point of
View.
Here we are going to understand the class and objects from the java
programming language point of view. But this is also applicable to any
OOP language like C# and C++.
Object-Oriented Programming
Class:
A class is simply a user-defined data type that represents both state and
behavior.
The state represents the properties and behavior is the action that
objects can perform.
A class is the blueprint/plan/template that describes the details of an
object.
A class is composed of three things i.E. A name, attributes, and
operations.
Object-Oriented Programming
Object
Object is an instance of a class.
A class is brought live by creating objects.
All the members of a class can be accessed through the object.
Object-Oriented Programming
How can we create a Class and Object in Java?
The point that you need to remember is, to create a class you need to use the class keyword while
if you want to create an object of a class then you need to use the new keyword.
Object-Oriented Programming
Difference between Class and Objects in Java ?
Object-Oriented Programming
Difference between Class and Objects in java
class object
A class is a template for creating
The object is an instance of a class.
objects in program.
A class is a logical entity Object is a physical entity
A class does not allocate memory Object allocates memory space
space when it is created. whenever they are created.
You can create more than one object
You can declare class only once.
using a class.
Classes can’t be manipulated They can be manipulated.
Each and every object has its own
It doesn’t have any values which are
values, which are associated with the
associated with the fields.
fields.
You can create class using “class” You can create object using “new”
keyword. keyword in Java