[go: up one dir, main page]

0% found this document useful (0 votes)
70 views25 pages

Object-Oriented Programming: Rhea Mae L. Perito, Msis Subject Instructor

This document introduces object-oriented programming concepts including objects, classes, inheritance, interfaces, and packages. An object contains state in fields and exposes behavior through methods. A class acts as a blueprint for objects and can use inheritance to share state and behavior. Interfaces define contracts for methods without implementation. Packages organize related classes and interfaces, and application programming interfaces are large class libraries.

Uploaded by

Rhea Mae Perito
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views25 pages

Object-Oriented Programming: Rhea Mae L. Perito, Msis Subject Instructor

This document introduces object-oriented programming concepts including objects, classes, inheritance, interfaces, and packages. An object contains state in fields and exposes behavior through methods. A class acts as a blueprint for objects and can use inheritance to share state and behavior. Interfaces define contracts for methods without implementation. Packages organize related classes and interfaces, and application programming interfaces are large class libraries.

Uploaded by

Rhea Mae Perito
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Object-Oriented

Programming
RHEA MAE L. PERITO, MSIS
SUBJECT INSTRUCTOR
Introduction
This lesson will introduce you to objects,
classes, inheritance, interfaces, and packages.
Each discussion focuses on how these concepts
relate to the real world, while simultaneously
providing an introduction to the syntax of the
Java programming language.
Object

are key to understanding object-


oriented technology.
Look around right now and you'll find
many examples of real-world objects.
Two Characteristics of Real-world
Objects
state
Behavior

Ex.
Dog has state (name, color, breed) and behavior
(barking, fetching, wagging tail)
The World of OOP
Software Objects
 are conceptually similar to real-world
objects: they too consist of state and
related behavior.
Object

stores its state in fields (variables in some


programming languages) and exposes its
behavior through methods (functions in
some programming languages).
Methods

 operate on an object's internal state


and serve as the primary mechanism
for object-to-object communication.
Data Encapsulation

a fundamental principle of object-


oriented programming.
hiding internal state and requiring all
interaction to be performed through an
object's methods.
Bicycle Example
By attributing state (current speed,
current pedal cadence, and current gear)
and providing methods for changing that
state, the object remains in control of how
the outside world is allowed to use it.
Bundling code into individual software
objects provides a number of benefits,
including:
Modularity: The source code for an object can be
written and maintained independently of the
source code for other objects. Once created, an
object can be easily passed around inside the
system.
Information-hiding:
By interacting only with an object's methods,
the details of its internal implementation
remain hidden from the outside world.
Code re-use:
If an object already exists (perhaps written by
another software developer), you can use that
object in your program. This allows
specialists to implement/test/debug complex,
task-specific objects, which you can then
trust to run in your own code.
Pluggability and debugging ease:
If a particular object turns out to be
problematic, you can simply remove it from
your application and plug in a different
object as its replacement. This is analogous
to fixing mechanical problems in the real
world. If a bolt breaks, you replace it, not the
entire machine.
Class
is the blueprint from which individual
objects are created.
Ex.
bicycle is an instance of the class of
objects known as bicycles.
Bicycle Class
class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;

void changeCadence(int newValue){


cadence = newValue;
}
void changeGear(int newValue){
gear = newValue;
}
void speedup(int increment){
speed = speed + increment;
}
void applyBrakes(int decrement){
speed = speed – decrement;
}
void printStates(){
System.out.println(“cadence:” +
cadence + “ speed:” +
speed + “ gear:” + gear);
)
}
Inheritance
Object-oriented programming allows
classes to inherit commonly used state
and behavior from other classes.
In the Java programming language,
each class is allowed to have one direct
superclass, and each superclass has the
potential for an unlimited number of
subclasses:
class MountainBike extends Bicycle {
 
// new fields and methods defining
// a mountain bike would go here
 
}
Interface
 is a group of related methods with
empty bodies.
form a contract between the class and
the outside world, and this contract is
enforced at build time by the compiler.
Package
is a namespace that organizes a set of
related classes and interfaces.
Application Programming
Interface (API)
An enormous class library (a set of
packages)

You might also like