OOPS
OOPS
1
Object-oriented programming
and etc
2
Advantages of OOP :
– Ability to represents Real Word Entities
– Code Reusability
– Easy Management
– Maintenance
– Abstraction
– Polymorphism
Disadvantages:
– Complex Design
– Many skills
– Large size & Many Instructions
– Slow Speed
3
OOP CONCEPTS
4
OOP CONCEPTS
• Class
• Object
• Encapsulation
• Abstraction
• Inheritence
• Polymorphism
• Message Passing
• Association
• Aggregation
• Composition
5
6
OBJECTS
• An real time / runtime entity that has state and behavior is known as
an object e.g. chair, bike, marker, pen, table, car etc.
• It can be physical or logical (tangible and intangible). The example
of an intangible object is the banking system.
• The object is an instance of a class.
7
8
CLASS
9
• It is a template or blueprint that describes the kinds of state and
behavior that objects of its type support.
• It is a template or blueprint from which objects are created.
• A class is a collection of objects which have common properties.
• It is a logical entity. It can't be physical.
10
Member of a class
11
Encapsulation
12
• Encapsulation is the mechanism that binds together code and the
data it manipulates, and keeps both safe from outside interference
and misuse.
• One way to think about encapsulation is as a protective wrapper
that prevents the code and data from being arbitrarily accessed by
other code defined outside the wrapper.
• Access to the code and data inside the wrapper is tightly controlled
through a well-defined interface.
13
• We can achieve encapsulation in Java by:
• Declaring the variables of a class as private.
• Providing public setter and getter methods to modify and view the
variables values.
14
Abstraction
15
• For Car as an example, people do not think of a car as a set of tens
of thousands of individual parts. They think of it as a well-defined
object with its own unique behavior.
• For driving car as an example, while driving a car, you do not have
to be concerned with its internal working. Here you just need to
concern about parts like steering wheel, Gears, accelerator, etc.
16
Making phone call as abstraction
For example phone call, we don't know the internal processing, to make a call, it is
enough to know the phone number.
17
• An abstraction is an act of representing essential features without
including background details.
• It basically deals with hiding the details and showing the essential
things to the user
• It is a technique of creating a new data type that is suited for a
specific application.
• Helps to reduce complexity.
18
• You can achieve abstraction in two ways:
• a) Abstract Class
• b) Interface
19
Inheritance
20
• Inheritance is the process by which one object acquires the
properties and behaviors of the parent object and reuse it .
• This is important because it supports the concept of hierarchical
classification i.e It’s creating a parent-child relationship between two
classes.
21
• A class which inherits the properties is known as Child Class
whereas a class whose properties are inherited is known as Parent
class.
• The child acquires the properties and behaviors of the parent object
in addition to that it has its own the properties and behaviors.
• It provides code reusability
22
23
Polymorphism
24
7) Association
Association is a relationship between two objects. It defines the
diversity between objects. In this OOP concept, all object have their
separate lifecycle, and there is no owner. For example, many
students can associate with one teacher while one student can also
associate with multiple teachers.
Aggregation
• In this technique, all objects have their separate lifecycle. However,
there is ownership such that child object can’t belong to another
parent object. For example consider class/objects department and
teacher. Here, a single teacher can’t belong to multiple
departments, but even if we delete the department, the teacher
object will never be destroyed.
25
Composition
• A composition is a specialized form of Aggregation. It is also called
"death" relationship. Child objects do not have their lifecycle so
when parent object deletes all child object will also delete
automatically. For that, let’s take an example of House and rooms.
Any house can have several rooms. One room can’t become part of
two different houses. So, if you delete the house room will also be
deleted.
• Message passing
26
27