You are on page 1of 18

Object Oriented Programming (OOP)

Academic Year 2023 24 Sem II


Jarray NAJMEDDINE
ISMAI Kairouan

1
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 : Imperative :
• Procedural (Non-Structured) Programming
• Object Oriented Programming
• Some of the programming languages are designed to
support one paradigm and some of them support
multiple paradigms.

2
Procedural 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 : C , Pascal
• Limitation
• Difficult to maintain code as size of program
increases
• Code cannot be reused
• Difficult to test code
3
Object Oriented Programming
• Paradigm for problem solving by interaction among objects
• 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.
4
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

5
Programmation Language
• Object oriented programming (OOP) is facilitated by
languages that offer features for creating and
manipulating objects.
• Key languages supporting OOP include
• Java : SpringBoot
• Python
• C#: Dot. Net
• JavaScript: Angular
• Dart: Flutter

6
OOP……

• Writing object-oriented programs involves


• creating classes,
• creating objects from those classes, a
• creating applications, which are stand alone
executable programs that use those objects.

7
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:
• Object
• Class and Method
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction

8
Object
• Object is an instance of a class that holds data
(values) in its variables. Data can be accessed by its
functions
• Objects are fundamental runtime entities in object-
oriented systems, representing various entities such
as a person, a place, a bank account, or a table of
data.
• They encompass both physical and logical from Real
world object, each with its own identity, state, and
behavior, like a Pencil , apple ,Book , Bag Or Board

9
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 Flower’s
engineering drawings, which house the design of
an accelerator pedal, steering wheel, and so on.

10
Encapsulation

• Mechanism by which we combine data and the


functions that manipulate the data into one unit
• 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 in Java 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.
• Objects & Classes enforce encapsulation

11
Abstraction
• Extracting essential properties and behavior of
an entity
• Class represents such an abstraction and is
commonly referred to as an abstract data type
• Abstraction in object-oriented programming
hides complex implementation details from
users.
• It allows users to interact with objects based on
their functionality rather than their internal
workings.
• This concept is similar to how a car's pedals
abstract away the mechanics of acceleration
and braking.

12
Inheritance
• Inheritance is the process in object-oriented
programming where a class can acquire the
attributes and methods of another class, promoting
a hierarchical organization of information.
• This mechanism allows a subclass, also known as a
derived or child class, to inherit properties from a
superclass, referred to as a base or parent class.
• With inheritance, the subclass can access and
utilize the features of the superclass without
needing to redefine them, enhancing code
reusability and maintainability.
• Inheritance facilitates the addition of new
functionalities to existing classes without modifying
their original structure, thereby promoting
flexibility and scalability in software development.

13
Polymorphism
• Polymorphism, originating from Greek roots meaning
"many shapes," refers to entities in Java that can take
on multiple forms, such as operators, constructors, or
methods.
• This concept allows operations to exhibit different
behaviors depending on the type of data involved. For
instance, addition can yield a sum for numerical
operands, while concatenating strings.
• Polymorphism enables flexibility and versatility in
programming, as it allows operators to perform
distinct actions based on the context in which they are
used.
• In Java, polymorphism facilitates code reusability and
enhances the readability and maintainability of
programs by allowing methods to be defined more
generically, capable of handling various types of input.

14
Benefits of OOP
Modular programming
enables the creation of Data hiding enhances
OOP provides numerous Inheritance reduces code
programs using reusable program security by
advantages for both duplication and allows for the
modules, saving development preventing unauthorized
programmers and users: extension of existing classes.
time and enhancing access to sensitive data.
productivity.

Object mapping simplifies the Object based partitioning Data centered design captures Object oriented systems scale
representation of real world facilitates project organization model details effectively for seamlessly from small to large
entities in the program. and management. implementation. projects.

Challenges such as the


The applicability of these availability of object libraries
Message passing simplifies Object oriented approaches
features varies depending on and evolving technology must
communication between effectively manage software
project requirements and be addressed to fully realize
objects and external systems. complexity.
programmer preferences. the benefits of OOP and
ensure successful reuse.
15
Disadvantages of OOP
Complexity: Performance Overhead: Learning Curve:
Initial Effort:
Can lead to complex class May introduce performance Challenging for novice
Requires extra effort to overhead due to dynamic programmers to grasp
hierarchies, making
accurately model classes dispatch and memory concepts like inheritance
understanding and
and subclasses initially. allocation. and polymorphism.
maintenance difficult.

Abstraction Issues: Parallelization Challenges:


Selective Suitability: Inheritance Problems: Can
May pose challenges in
Over abstraction can make lead to issues like the
Not universally suitable for concurrent programming
code difficult to modify or diamond problem and tight
all problem domains. due to shared mutable
extend. coupling.
state.

Testing Difficulty:
Misuse Potential: Improper Encapsulation Concerns: Performance Concerns:
use can result in code that's Encapsulation can be Testing can be challenging, May lead to performance
hard to maintain and broken, leading to especially with complex bottlenecks compared to
debug. unexpected behavior. hierarchies and other paradigms.
dependencies.
16
Application of OOP
Real world business systems tend to be intricate, featuring numerous
objects with intricate attributes and methods. OOP proves invaluable in
tackling such complexity, offering simplification for intricate problems.
Key domains where OOP finds promising application include:

Hypertext,
Simulation and Object oriented
Real time systems hypermedia, and
modeling databases
expertext

Neural networks and Decision support


AI and expert CIM/CAM/CAD
parallel and office
systems systems
programming automation systems

17
• Kairouan , Tunisie
• Higher Institute of Applied Mathematics and Computer Science
• For further information please contact
Email: najmejarray@gmail.com

18

You might also like