YMCA COMPREHENSIVE INSTITUTE
Object Oriented Programming
TOPIC 1
Introduction to OOP
© YCI – 2025.
BIT 1203 04/14/2025
Outline
2
Review of programming paradigms
Objects and classes
Methods and Functions
Principles/features of OOP
Class library
© YCI – 2025. 04/14/2025
Paradigms of Programming
A programming paradigm is a :
Style of programming.
Way of representing concepts and abstraction
which are used to represent the elements of a
program and steps that compose a computation
Common programming paradigms
Non-Structured (Procedural) Programming
Structured Programming
Object Oriented Programming
Some of the programming languages are
designed to support one paradigm and some of
them support multiple paradigms.
© YCI – 2025. 04/14/2025
Non-Structured Programming
Code is written in a single
continuous program
Lines may be numbered or
labelled
Allows control flow to jump
to any line
Leads to “spaghetti” code
Program works on data
directly
An Example
Basic programming
language
© YCI – 2025. 04/14/2025
Limitation
Difficult to maintain code as size of
program increases
Code cannot be reused
Difficult to test code
© YCI – 2025. 04/14/2025
Structured Programming
Program is divided into smaller subtasks or
modules
Helps in modularity - Functions
Complexity made manageable
Maintenance made easier
Control flow between modules can be defined
in a structured manner
Each module has inputs and a defined output
Good model for small-medium sized projects
Examples
C, Fortran and Pascal
© YCI – 2025. 04/14/2025
Limitations
Emphasis is more on functionality, less on
data
Data and functionality are treated
separately
Data Structures(variables) and algorithms
(functions)
Does not represent real world objects
Data may not be secure
Functions are less reusable.
It is very difficult to copy a function from one
program and reuse in another program
© YCI – 2025. 04/14/2025
Object Oriented Programming
This is a programming paradigm that deals with
modeling of real world objects into a computer
program.
Real world objects have;
Properties
Exhibit behavior and interacts with other objects
And State
There are date objects, time objects, audio objects,
video objects, automobile objects, people objects, etc.
Almost any noun can be reasonably represented as a
software object in terms of
Attributes(e.g., name, color and size) – variables and
Behaviors(e.g., calculating, moving and communicating) –
Methods.
© YCI – 2025. 04/14/2025
Why OOP?
OOP - Is a methodology or paradigm to design a
program using classes and objects.
Modularity — Separating entities into separate
logical units makes them easier to code,
understand, analyze, test, and maintain.
Data hiding (encapsulation) — The implementation
of an object’s private data and actions can change
without affecting other objects that depend on it.
Code reuse through:
Inheritance — Objects can inherit state and behavior
of other objects
Composition — Objects can contain other objects
Easier design due to natural modeling
© YCI – 2025. 04/14/2025
Important terms in OOP
Objects
Any real world entity that has an identity,
state and behavior is known as an object.
For example: chair, pen, table, keyboard, bike
etc. It can be physical and logical.
© YCI – 2025. 04/14/2025
Characteristics of objects:
Objects are characterised by
State (what the objects have)
Behaviour (what the objects do)
Identity (what makes them unique)
For Example; consider a car as an object
Its state include
Speed, Gear, Direction, Fuel level, Engine
temperature
Its behaviors include:
Change Gear, Go faster/slower, Go in reverse,
Stop, Shut-off
Its identity is:
VIN, License Plate
© YCI – 2025. 04/14/2025
Life Time of an Object
An object Survives as long as the
instance variable referencing it will
survive.
If instance variable is set to null, the
object is destroyed.
The process of disposing off dead objects
is called Garbage Collection.
© YCI – 2025. 04/14/2025
Methods and Classes
Performing a task in a program requires a method.
The method houses the program statements that
actually perform its tasks.
The method hides these statements from its user,
Just as the accelerator pedal of a car hides from the
driver the mechanisms of making the car go faster.
In OOP, we create a program unit called a class
To house the set of methods that perform the class’s
tasks.
A class is similar in concept to a car’s engineering
drawings, which house the design of an accelerator
pedal, steering wheel, and so on.
© YCI – 2025. 04/14/2025
OOP ..
Writing object-oriented programs
involves creating
Classes,
Objects from those classes (instantiation),
Applications,
Stand-alone executable programs that use
those objects.
© YCI – 2025. 04/14/2025
OOP ..
Instantiation
Building objects from classes
The process of doing this is called instantiation.
An object is then referred to as an instance of
its class.
Reuse
A class can be used many times to build
many objects.
Reuse of existing classes when building
new classes and programs saves time and
effort
Reuse also helps you build more reliable
© YCI – 2025. 04/14/2025
and effective systems
Attributes and Instance
Variables
An object has attributes that it carries along as
it’s used in a program.
These attributes are specified as part of the
object’s class.
For example,
A bank account object has a balance attribute that
represents the amount of money in the account.
Each bank account object knows the balance in
the account it represents, but not the balances of
the other accounts in the bank.
Attributes are specified by the class’s instance
variables.
© YCI – 2025. 04/14/2025
Key object oriented Concepts
Object Oriented programming is a
programming style that is associated
with the concept of Class, Objects and
various other concepts revolving around
these two
The four major principles of OOP are:-
Encapsulation
Inheritance
Polymorphism
Abstraction
© YCI – 2025. 04/14/2025
Encapsulation
It is a mechanism of hiding the internal details
and allowing a simple interface which ensures
that the object can be used without having to
know how it works.
Encapsulation is a mechanism of wrapping the
data (variables) and code acting on the data
(methods) together as a single unit.
In encapsulation, the variables of a class will be
hidden from other classes, and can be
accessed only through the methods of their
current class.
Therefore, it is also known as data hiding.
© YCI – 2025. 04/14/2025
Inheritance
Inheritance can be defined as the
process where one class acquires the
features (attributes & methods) of
another.
With the use of inheritance the
information is made manageable in a
hierarchical order.
The class which inherits the properties of
other is known as subclass (derived
class, child class) and the class whose
properties are inherited is known as
superclass (base class, parent class).
© YCI – 2025. 04/14/2025
Polymorphism
In Greek, Poly means many and morph
means shapes or forms.
So. Polymorphism refers to any entity which
takes many forms.
Polymorphism refers to any entity
whether it is an operator or a
constructor or any method which
takes many forms or can be used for
multiple tasks either while compiling
or running a program.
© YCI – 2025. 04/14/2025
Abstraction
As per dictionary, abstraction is the quality of dealing with
ideas rather than events.
For example,
The accelerator pedal hides from the driver the complex
mechanisms that actually make the car go faster.
The brake pedal hides the mechanisms that slow the car,
and
the steering wheel “hides” the mechanisms that turn the
car.
Likewise in Object-oriented programming,
Abstraction is a process of hiding the implementation
details from the user, only the functionality will be provided
to the user.
In other words, the user will have the information on what the
object does instead of how it does it.
© YCI – 2025. 04/14/2025
Python Class Library Overview
Popular Built-in Classes and Libraries:
- list, dict, set, tuple (data structures)
- datetime (date and time management)
- os (operating system interactions)
- math (mathematical operations)
Example:
import datetime
today = datetime.date.today()
print(f"Today's date: {today}")
© YCI – 2025. 04/14/2025
Thank you
© YCI – 2025. 04/14/2025