Introduction to Object-oriented
programming and software
development
Lecture 1
Procedural Programming
Traditional programming languages were
procedural.
C, Pascal, BASIC, Ada and COBOL
Programming in procedural languages
involves choosing data structures
(appropriate ways to store data), designing
algorithms, and translating algorithm into
code.
2
Procedural Programming
In procedural programming, data and
operations on the data are separated.
This methodology requires sending data to
procedure/functions.
3
Procedural Programming
Data Element
Function A
Function B
4
#include <iostream>
void read_data();
double addition (double,double);
void main ()
{
double num1, num2, double;
read_data();
cout << "Sum:"<<addition(num1,num2);
}
//function definition
void read_data ( ) {
cout << "enter 1st number" << endl;
cin >> num1;
cout << "enter 2nd numbber" << endl;
cin >> num2;
}
double addition(double n1, double n2)
{
return(n1+n2);
}
5
Object-Oriented Programming
Object-oriented programming is centered on
creating objects rather than procedures/
functions.
Objects are a melding of data and
procedures that manipulate that data.
Data in an object are known as attributes.
Procedures/functions in an object are known
as methods.
6
Object-Oriented Programming
Object
Attributes (data)
Methods
(behaviors / procedures)
7
public class Add {
private double num1,num2;
public Add() {
num1 = 1.3;
num2 = 3.4;
sum = 0.0;
}
public double getNum1() {
return num1;
}
public double addnumber(double n1,double n2) {
return (n1+n2);
}
}
public class TestAdd {
public static void main(String[] args)
{
Add a = new Add();
System.out.println("Sum:"+a.addnumber(getNum1(),num2));
}
}
8
Object-Oriented Programming
Object-oriented programming combines data and
behavior via encapsulation.
Data hiding is the ability of an object to hide data
from other objects in the program.
Only an objects methods should be able to directly
manipulate its attributes.
Other objects are allowed to manipulate an object’s
attributes via the object’s methods.
This indirect access is known as a programming
interface.
9
Object-Oriented Programming
Object
Programming
Interface
Attributes (data)
typically private to this object
Other
objects
Methods
(behaviors / procedures)
10
Object-Oriented Programming
Languages
Pure OO Languages
Smalltalk, Eiffel, Actor, Java
Hybrid OO Languages
C++, Objective-C, Object-Pascal
11
VOCABULARY OF OOP
CLASS
OBJECT
ENCAPSULATION implement DATA HIDING
INHERITANCE
POLYMORPHISM
12
CLASS
The most important term.
A class is the template or blueprint from which objects
are actually made.
All code that you write in Java is inside a class.
The standard Java library supplies several thousand
classes.
You can create your own classes in Java to describe
the objects of the problem domains of your applications
and to adapt the classes that are supplied by the
standard library to your own purposes.
A class encapsulates the attributes and actions that
characterizes a certain type of object.
13
OBJECTS
Classes can be used to instantiate as many
objects as are needed.
Each object that is created from a class is
called an instance of the class.
A program is simply a collection of objects
that interact with each other to accomplish a
goal.
14
Classes and Objects
Kancil object
The Car class defines the attributes
and methods that will exist in all objects
that are an instances of the Car class.
The Kancil object is an
instance of the Car class.
Car class
The Nazaria object is an
instance of the Car class.
Nazaria object
15
ENCAPSULATION
key concept in working with objects
.
Combining data and behavior
in one package and hiding the
implementation of the data
from the user of the object.
The data in an object are
called its instance fields, and
the procedures that operate on
the data are called its
methods.
The key to making
encapsulation work is to have
methods never directly
access instance fields in a
class other than their own.
Programs should interact with
object data only through the
object's methods.
By encapsulating object data,
you maximize reusability,
reduce data dependency, and
minimize debugging time.
16
DATA HIDING implemented through
ENCAPSULATION
Data Hiding is important for several reasons.
It protects of attributes from accidental
corruption by outside objects.
It hides the details of how an object works, so
the programmer can concentrate on using it.
It allows the maintainer of the object to have
the ability to modify the internal functioning of
the object without “breaking” someone else's
code.
17
Allow CODE REUSABILITY
Object-Oriented Programming (OOP) has encouraged
component reusability.
A component is a software object contains data and
methods that represents a specific concept or service.
Components typically are not stand-alone programs.
Components can be used by programs that need the
component’s service.
Reuse of code promotes the rapid development of larger
software projects.
18
INHERITANCE
Inheritance is the ability of one class to extend the
capabilities of another.
it allows code defined in one class to be
reused in other classes
Consider the class Car. A Car is a specialized form
of the Vehicle class.
So, is said that the Vehicle class is the base or parent
class of the Car class.
The Car class is the derived or child class of the
Vehicle class.
19
INHERITANCE
Vehicle represents all
of the generic attributes
and methods of a vehicle.
Vehicle
Vehicle is the
parent class.
is-a relationship
Car and Truck are
child classes of
Vehicle.
Car
Truck
Car and Truck are
Specialized versions of
a Vehicle.
20
POLYMORPHISM
Polymorphism means "many forms."
A reference variable is always of a single,
unchangeable type, but it can refer to a
subtype object.
A single object can be referred to by reference
variables of many different types—as long as
they are the same type or a supertype of the
object.q The reference variable's type (not the
object's type), determines which methods can
be called!
Polymorphism allows extensibility.
21
Object Orientation Principle
Divide-and-conquer
Encapsulation and Modularity
Public Interface
Information Hiding
Generality
Extensibility
Abstraction
22
Divide-and-Conquer Principle
The first step in designing a program is to divide
the overall program into a number of objects that
will interact with each other to solve the problem.
Problem solving: Break problems (programs) into
small, manageable tasks.
23
Encapsulation Principles
The next step in designing a program is to decide
for each object, what attribute it has and what
actions it will take.
The goal is that each object is a self-contained
module with a clear responsibility and the
attributes and actions necessary to carry out its
role
Problem solving: Each object knows how to solve
its task and has the information it needs.
24
Interface Principles
Object
Programming
Interface
Attributes (data)
typically private to this object
Other
objects
For object to work
cooperatively and
efficiently, we have to
clarify exactly how they
are to interact, or
interface, with one
another.
Each object should
present a clear public
interface that
determines how other
objects will be used.
Methods
(behaviors / procedures)
25
Information Hiding Principles
To enable objects to work
together cooperatively,
certain details of their
individual design and
performance should be
hidden from other objects.
Each object should shield
its users from unnecessary
details of how it performs
its role.
26
Generality Principles
To make an object as
generally useful as possible,
we design them not for a
particular task but rather for
a particular kind of task.
This principle underlies the
use of software libraries.
Objects should be designed
to be as general as possible.
Objects are designed to
solve a kind of task rather
than a singular task.
27
Extensibility Principles
Shape
Circle
Cone
Rectangle
Triangle
Cylinder
One of the strength of the object-oriented approach is
the ability to extend an object’s behavior to handle new
tasks.
An object should be designed so that their functionality
can be extended to carry out more specialized tasks.
28
Abstraction Principles
is the ability to focus on the important
features of an object when trying to
work with large amounts of
information.
ignore many of the attributes that
characterize the real objects and focus
only on those attributes that are
essential for solving a particular
problem.
29
Example of
abstraction
30
Benefits of Object-oriented
programming
Save development time (and cost) by reusing code
once an object class is created it can be used
in other applications
Easier debugging
classes can be tested independently
reused objects have already been tested
31
Self-test: Introduction to Object Oriented
Programming
1. What are the seven basic principles of object
orientation? Provide a brief description of
each.
2. State the benefits of object oriented
programming.
32
© Copyright 2026 Paperzz