Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Object Oriented Programming

INTRODUCTION
OOP is like a solving a problem by creating objects is one of the most
popular approaches in programming. It aims to implement real-world
entities like inheritance, hiding, polymorphism, etc. and to bind together
the data and the functions that operates on them so that no other part
of the code can access by this data except that function.
OOP’s CONCEPTS

1. Class
2. Object
3. Method and Method Passing
4. Pillars of OOP’s
a. Abstraction
b. Encapsulation
c. Inheritance
d. Polymorphism
I. Compile-time polymorphism
II. Runtime polymorphism
DRY
DRY stands for Do not Repeat Yourself
- It focuses on code reusability.
01
CLASS
Class
It represents the set of properties or methods that are common to all objects of one
type. In general, class declarations can include these components, in order:

■ Modifiers: A class can be public or has default access.


■ Class keyword: class keyword is used to create a class.
■ Class name: The name should begin with an initial letter (capitalized by convention).
■ Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the
keyword extends. A class can only extend (subclass) one parent.
■ Interfaces(if any): A comma-separated list of interfaces implemented by the class, if
any, preceded by the keyword implements. A class can implement more than one
interface.
■ Body: The class body is surrounded by braces, { }.
CLASS Object Instantiation OBJECT

Contains information to create a valid Object.


02
OBJECT
Object
An instantiation of a class. When a class is defined, a template (information) is
defined. Memory is allocated only after an object instantiation.

■ State: It is represented by attributes of an object. It also reflects the properties of an


object.
■ Behavior: It is represented by methods of an object. It also reflects the response of an
object with other objects.
■ Identity: It gives a unique name to an object and enables one object to interact with other
objects.
CLASS Dog

Attributes
Breed
Dog 1 Age Dog 3
Color

Behavior
Bark
Dog 2 Dog 4
Sleep
Eat
Instantiation
In Java, instantiation mean to call the constructor of a class that creates an instance
or object of the type of that class. It occupies the initial memory for the object and
returns a reference. It also provides the blueprint for the object

function Animal (numlegs, mysound) {


this.leg = numlegs;
this.sound = mysound;
}
var lion = new Animal (4, “roar”);
var cat = new Animal (4, “meow”);
var dog = new Animal (4, “bark”);
PROPERTIES METHODS
Properties can be viewed as data that Meanwhile, methods are essentially
describes the Object that can be created functions that define the types of behaviors
from the class. the Object can takes.
OOP’s Terminology

01 Abstraction Hiding internal details.

The act of putting various


02 Encapsulation components together.

The act of deriving new


03 Inheritance things from existing things.

04 Polymorphism One entity, many forms.

You might also like