Object Oriented
Programming II
CSC 202
PROGRAMMING PARADIGMS
• Paradigm is defined as the various systems of ideas that have been used to guide the design of PLs
although the design of a given language may reflect the influence of more than one paradigm.
• Paradigm are different ways or styles in which a given program or programming language are
organized.
• It is also a typical example or model that form the basis of something; a philosophical or theoretical
framework of any kind.
• Programing Paradigms are categorised as : Imperative Programming and Declarative Programming
these include:
• Structural Paradigm
• Procedural Programming
• Object Oriented Programming
• Logic Programming
• Functional Programming
PROGRAMMING
PARADIGMS
IMPERATIVE PARADIGM DECLARATIVE PARADIGM
OBJECT ORIENTED PROCEDURAL FUNCTIONAL
PROGRAMMING PROGRAMING PROGRAMING
STRUCTURED
PROGRAMMING LOGIC PROGRAMING
Programming Paradigms
Definitions
• Major Paradigms mostly referred to:
• Imperative Programming – is the programming style based on specific
operations described through statements, consequent commands and
actions. Procedural and Object Oriented programming paradigms are all
derivatives of the imperative style. Languages which reflect this paradigm
recognize the fact that computers have re-usable memory that can change
state; they are characterized by statements which affect the state of the
machine
• Declarative Programming – focuses on the what should be achieved rather
than the how exactly; the command flow is not being specified but the
focus is on the result. The functional PLs are declarative.
• Procedural Programming – sometimes referred to as Conventional and/or
Traditional is imperative-based type of programming and can be
synonymous. It is built around the idea of building procedures, functions
and/or routines. Although functions are also represented in the Functional
programming, the Procedural style usually refers to the imperative paradigm.
• Structural Programming – also known as modular programming is a term
referring to PLs that support structured flow-control; it focuses on separation
of concerns, modularity and reusability. All modern languages are structural,
both imperative and declarative. Only old languages like Assembly Language
do not support any structural syntax.
• Object Oriented Programming – OOP paradigm is quite popular today,
floating around the idea of classes (templates) and concrete instances
representing objects from the real world and domain rather than from
machine point of view. Encapsulation, Polymorphism, Abstraction and
Inheritance are the top properties that characterize the Object Oriented
programming style. Even though there are languages that are procedural in
nature, some can be classified as object oriented also
• Functional Programming – is a subtype of the declarative style.
Programs written in functional languages are executed by evaluation
expressions rather than statements that change some state, e.g. state
of a variable. Although Functional programming is also structured,
some of the control-flow constructs are not presented. They got only
one return value and are deterministic; in pure functional languages,
there are no loop statements; the only way is through recursion
(repetition of steps to give result).
• Logic Programming – this views computation as automated reasoning
over a corpus of knowledge. Facts about the problem domain are
expressed as logic formulae, and programs are executed by applying
inference rules over them until an answer to the problem is found, or
the collection of formulae is proved inconsistent. This paradigm also
have the tendency of a declarative nature. Logic languages are useful
for expressing problems where it is not obvious what the functions
should do; it focuses on predicate logic.
Comparison of OOP with Other Programming language
Function Oriented Programming Object Oriented Programming
User defined types Classes
Variables Objects
Structure members Instance variables
Functions Methods
Function call Message passing
Procedure Oriented Programming Object Oriented Programming
program is divided into small parts called functions. program is divided into parts called objects
Importance is not given to data but to functions as well as Importance is given to the data rather than
sequence of actions to be done. procedures or functions because it works
as a real world.
follows Top Down approach. OOP follows Bottom Up approach.
It does not have any access specifier. OOP has access specifiers named
Public, Private, Protected, etc.
Data can move freely from function to function in the system. objects can move and communicate with
each other through member functions
To add new data and function in POP is not so easy OOP provides an easy way to add new data and function.
Most function uses Global data for sharing In OOP, data can not move easily from function to function it can be
that can be accessed freely from function to function to function, kept public or private so we can control the access of data.
in the system.
it does not have any proper way for hiding data so it is less secure. OOP provides Data Hiding so provides more security
. Overloading is not possible. In OOP, overloading is possible in the form of
Function Overloading and Operator Overloading.
0. Example of Procedure Oriented Example of Object Oriented Programming are :
Programming are : C, VB, FORTRAN, Pascal. C++, JAVA, VB.NET, C#.NET, Phyton, e.t.c.
What is object-oriented programming (OOP)?
• Object-oriented programming (OOP) is a computer programming model that
organizes software design around data, or objects, rather than functions and
logic.
• An object can be defined as a data field that has unique attributes and
behavior.
• OOP focuses on the objects that developers want to manipulate rather than the
logic required to manipulate them.
• This approach to programming is well suited for software that is large, complex
and actively updated or maintained.
• This includes programs for manufacturing and design, as well as mobile
applications. For example, OOP can be used for manufacturing system
simulation software.
Benefits of OOP
• The organization of an object-oriented program also makes the
method beneficial for collaborative development, where projects are
divided into groups.
• Additional benefits of OOP include
• code reusability,
• scalability and
• efficiency.
Examples of Objects
• Examples of an object can range from physical entities, such as a human
being who is described by properties like name and address
Structure of object-oriented programming
• The structure, or building blocks, of object-oriented programming include the
following:
• Classes are user-defined data types that act as the blueprint for individual objects,
attributes and methods.
• Objects are instances of a class created with specifically defined data. Objects can
correspond to real-world objects or an abstract entity. When class is defined initially,
the description is the only object that is defined.
• Methods are functions that objects can perform. They are defined inside a class that
describe the behaviors of an object. Each method contained in class definitions starts
with a reference to an instance object. Additionally, the subroutines contained in an
object are called instance methods. Programmers use methods for reusability or
keeping functionality encapsulated inside one object at a time.
• Attributes represent the state of an object. In other words, they are the
characteristics that distinguish classes. Objects have data stored in the attributes
field. Class attributes belong to the class itself and are defined in the class template.
Member functions and Classes
Member function:
Using the car example to introduce some key OOP concepts, a member function
performs a unique task in a program. It is what contains the statement(s) / codes
that actually perform the task. It hides these statements from its user, just the
same way the accelerator pedal hides the speed mechanism from the driver. A
class is a program unit created to house the set of member functions that carries
out the class’s possibly varying tasks. E.g. a bank class having withdraw as a
member function
Attributes and Data Members:
A car has attributes such as colour, number of doors, current speed etc. the car
attributes are part of the design in the engineering drawings. Every car maintains
its own attributes but not that of others. So also an object as its attributes as it is
used in a program. Attributes are specified by the class’s data members. E.g.
account balance as an attribute particular to each bank account object.
TUTOR MARKED ASSESSMENT
Assignments/Tasks for the students:
1. What is your understanding of Programming Paradigms
2. In programming, what is object orientation about
3. Define classes
4. What is an object