0% found this document useful (0 votes)
5 views

Chap-1-Introduction To Object-Oriented Programming

java oop concepts
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Chap-1-Introduction To Object-Oriented Programming

java oop concepts
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

INTRODUCTION

TO OBJECT-ORIENTED
PROGRAMMING

BBC 2, Object-oriented Programming (BUC2125)


Academic Year, 2023/ 2024, Semester – I
Chapter Learning
Outcomes
 By the end of this lecture, you should;
 Understand OOP language paradigm in relation to
traditional procedural programming languages,
 Understand benefits of OOP over POP,
 Understand the various OOP concepts, i.e.
objects, classes, attributes, methods operations,
 Understand the four pillars of Object-Oriented
Programming: Abstraction, Inheritance,
Encapsulation and Polymorphism.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 2 BBC-2 – MUBS
Introduction
 Programming is a creative process
involving instructing a computer on how
to do a task.
 A program is a set of instructions that tells a
computer what to do in order to solve a particular
problem.
• Alternatively as according to Niklaus Wirth,
– “a computer program = algorithms + data
structures”.

o An algorithm is a set of instructions for solving a


given computational problem.
© 2023 Prepared By Ddamba Abdul For
o A data structure is3 a construct
Chap-1: Introduction to Object-oriented used to organize
BBC-2 – MUBS
Programming
Programming Paradigm
 A programming paradigm is a…
 Fundamental style or approach to programming
that guides how software is designed, organized,
and written.

• A paradigm defines the principles, concepts, &


methodologies that programmers use to build the
structure and elements of computer programs.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 4 BBC-2 – MUBS
Kinds of Programming
Paradigms
 Different paradigms have evolved over
time to address various programming
challenges & needs.
 Some common programming paradigms include:
• Functional programming
• Imperative programming • Logical programming
• Procedural programming • Event-driven
• programming
Structured programming
• Declarative programming
• Object-oriented programming
• Multi-paradigm
• Concurrent programming
programming

 Programmers select a suitable programming


paradigm based on the needs of a particular
© 2023 Prepared By Ddamba Abdul For
Chap-1: Introduction to Object-oriented
Programming 5 BBC-2 – MUBS
OOP vs Procedural
 There are a number of alternative
approaches to the programming process,
however, two of the most important
programming approaches are;

 Procedural paradigm and the


 Object-oriented paradigm.

 You can write a program in either way but


there are notable differences between both
approaches.
Chap-1: Introduction to Object-oriented
Programming 6
© 2023 Prepared By Ddamba Abdul For
BBC-2 – MUBS
Procedure-oriented
Programming
 A type of imperative programming, that;
 Focuses on organizing code (a list of instructions)
into groups known as functions (procedures or
sub-routines).

• In this paradigm, the program is divided into a series


of procedures, each of which performs a specific task
or operation.
• These procedures can be called and reused as needed
to perform different tasks, promoting code modularity
and reusability.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 7 BBC-2 – MUBS
Procedure-oriented
Programming
 It focuses on process (functions) rather
than data
 Emphasis is given to the procedural process, i.e.
specifying a sequence of actions (algorithms) to
be performed.
• The functions (procedures) contain steps to be
performed that change the values of the program
variables.

 The data is then defined independently of the


procedures.
• This actually means that there’s
Chap-1: Introduction to Object-oriented
© 2023very little
Prepared attention
By Ddamba Abdul For
Programming 8 BBC-2 – MUBS
Illustration of a POP
Approach
 A program may involve around 8 tasks written in
a program with the help of 8 different functions
using the global data.Main
Program
(Global data)

Function (Procedure) Function (Procedure) Function (Procedure)


-1 -2 -3

Function (Procedure) Function


-4 (Procedure) - 5

Function (Procedure) Function (Procedure) Function (Procedure)


-6 -7 -8

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 9 BBC-2 – MUBS
Examples of POP
Languages
 Examples of popular
OOP Languages.
PURE POP languages
are;
Two examples of popular object-oriented
• C
• programming
Pascal
languages are Java and C++.
• Some
FORTRAN
other(Formula Translation)
well-known object-oriented
• COBOL (Common Business-Oriented Language)
programming languages include;
• Ada
• • BASIC
Simula,(Beginner’s All-purpose Symbolic
• Instruction
Smalltalk, Code)
• Eiffel,
• JADE,
• C#,

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 10 BBC-2 – MUBS
Features of POP
Approach
 Programs divided into functions or
procedures
 When program become larger, it is divided into
functions (procedures) & each function has
clearly defined purpose.

• Procedures, also known as a “set of subroutines” or a


“set of functions” are groups of logically related
instructions that accomplishes a particular task in a
step-by-step order.

• These procedures (functions) are called repeatedly in


© 2023 Prepared By Ddamba Abdul For
Chap-1: Introduction to Object-oriented
Programminga program to execute tasks performed
11 BBC-2 – MUBS by them.
Features of POP
Approach
 It employs an imperative programming
technique
 Imperative programming involves writing a
program as a series of instructions (procedural
statements) that can actively modify the program
data (variables or memory).
• Procedures operate on the data to change the values
contained in the variables.
• Imperative programming focuses on how, in the sense
that you express the logic of your program based on
how the computer would execute it.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 12 BBC-2 – MUBS
Features of POP
Approach
 Functions share and access global data
 POP languages consists of global data held in
variables, that is separated from procedures or
functions.

• All functions share & access the same global data


(variables).
• This data are more vulnerable to an inadvertent
change by a function, since it is shared by all the
functions of procedures.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 13 BBC-2 – MUBS
Features of POP
Approach
 Employs top-down approach in program
design
 Also known as step-wise design which is the
breaking down of entire program into smaller
manageable pieces to gain insight into its
computational sub-systems.

• Top-down approach first focus on abstract of overall


system, then later, it focuses on detail development.
• The programmer has to write code for main function.
In main function they will call other sub function. At
last they will write code for each sub function.
© 2023 Prepared By Ddamba Abdul For
Chap-1: Introduction to Object-oriented
Programming 14 BBC-2 – MUBS
Features of POP
Approach
 Free movement of data around the system
 Data moves openly around the system from
function to function.
• No security to data, i.e. POP approach does not have
any access specifiers that impose restrictions on the
data access by the program functions.
• This therefore gives program function absolute powers
to transform data from one form to another.
• In a large program it is very difficult to identify what
data is used by which function. This provides an
opportunity for bugs to creep in.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 15 BBC-2 – MUBS
Limitations of the POP
Approach
 There’s no restrictions by the procedures
to accessing the global data
 This causes program insecurity as data contained
in the program can be accessed freely from any
function present in the program.
• For example the new programmer can corrupt the
data accidentally by creating function.

 It is difficult to create new data types


 The ability to create the new data type of its own
is called extensibility.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 16 BBC-2 – MUBS
Limitations of the POP Approach
 Emphasis is put on procedures, than the
data
 Data is given a second class status even through
data is the reason for the existence of the
program.
• Therefore, for the case of large and more complex
program, changes and updates become more difficult
& time consuming.
– For example if new data is to be added, all the function
need to be modified to access the data.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 17 BBC-2 – MUBS
Limitations of the POP Approach
 Reduced Code Reusability
 The absence of class-based inheritance &
polymorphism in procedural languages can limit
code reusability, making it necessary to duplicate
code in some cases.

 Difficult to design
 POP’s functions and data structures have limited
support to model real-world objects and their
interactions.
• For example, in designing graphical user interface, the
focus is placed on what “functions, and data
© 2023 Prepared By Ddamba Abdul For
structures”
Chap-1: Introduction
Programming
are
to Object-oriented needed
18instead
BBC-2 –of which “menu,
MUBS
Object-oriented Programming
(OOP)
 OOP languages were designed to
overcome POP-related problems

 This was mainly done through combining the


process (function) and data into a unit called an
object.
• Thereby giving importance to relationships between
objects rather than procedural implementation details.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 19 BBC-2 – MUBS
Object-oriented Programming
(OOP)
 What is a OOP paradigm?
 The OOP approach uses objects, (instances of
classes) acting as data structures combining their
data (variables) and procedures (functions)
together with their interactions to analyze,
design, and implement software systems

• OOP is based on several fundamental principles and


concepts that facilitate design and creation of
software systems, i.e.;
– Objects, classes and their relationships
– Encapsulation
– Inheritance
© 2023 Prepared By Ddamba Abdul For
– Polymorphism
Chap-1: Introduction to Object-oriented
Programming 20 BBC-2 – MUBS
Illustration of a OOP
Approach
Object of the program interact by sending
messages to each other
Object A Object B

Data Data

Communication
Functions Functions

Object C

Functions

Data

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 21 BBC-2 – MUBS
Features of OOP
Approach
 Programs are divided into objects
 The building-block of OOP approach, is the object

• The object acts as a data structure


– Each object combines its own data with its own
functions (logic or methods or algorithms or
procedures) into a single unit.
– The procedures are written to manipulate these objects.
• Data in an object are known as attributes.
• Procedures/functions in an object are known as
methods.

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 22 BBC-2 – MUBS
Features of OOP
Approach
 Focus is on the data objects
 OOP is centered on creating objects rather than
procedures
 The program data have a principle / active role.

 Data and procedures are combined


(Encapsulation)
 Functions that operate on the data are tied
together in the data structure (object).

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 23 BBC-2 – MUBS
Features of OOP
 Object interactions
Approach
 Objects communicate with each other through
functions (methods).
• These functions are the procedures that allow various
program objects to interact so that they can perform
specified tasks

 Permits higher-level abstraction


 OOP is problem oriented, rather than process-
oriented
• It simulates a human thinking in the real world
– This is because a lot of real life problems involve things
that
Chap-1: Introduction to Object-oriented Bank, ©
are objects (e.g. 24 2023 Prepared By Ddamba Abdul For
Card, Spaceship, Bullet),
BBC-2 – MUBS
Programming
Features of OOP
Approach
 Access and sharing of the data is
restricted
 Data can’t freely move from one function to
another
• Internal object data can be hidden away from the
external functions.
– This is because data can be kept private and hidden
since it can be kept public or private. This ensures
program security.

 Flexibility
 OOP supports the creation of extensible and
adaptable
Chap-1: Introduction software systems
to Object-oriented
25
© 2023 Prepared By Ddamba Abdul For
BBC-2 – MUBS
Programming
Features of OOP
Approach
 Employs a bottom-up approach to
program design
 Program organization start from the bottom to the
top
• It means we make the smallest (simple) pieces of
program first and then use them to build a
bigger(complex) program.

 Code reusability
 A piece of code written earlier in a program can
be used later through “inheritance”.
© 2023 Prepared By Ddamba Abdul For
• By using inheritance, one
26 class
Chap-1: Introduction to Object-oriented
Programming
can
BBC-2 acquire the
– MUBS
Examples of OOP


Languages
Some
Examples
well-known
of OOP Languages.
object-oriented
programming
Two examples oflanguages include;
popular object-oriented
• programming
Java languages •areSimula
Java and C++.
• Some • Smalltalk
C++ other well-known object-oriented
• programming
C# languages •include;
Eiffel
• Python • JADE
• Simula,
• Ruby • Objective C
• • Swift
Smalltalk, • Delphi
• • PHP
Eiffel, • F#
• • Scala
JADE, • Perl
• • Kotlin
C#,
• VisualBasic.NET

© 2023 Prepared By Ddamba Abdul For


Chap-1: Introduction to Object-oriented
Programming 27 BBC-2 – MUBS
Advantages of OO Programming
 OOP offers several benefits as seen below;
 Ease in software design
 Development of re-usable software
 Software extensibility
 Improved software maintainability
 Faster development
 Lower cost of development
 Higher-quality software
 Development of secure programs
 Modularity
© 2023 Prepared By Ddamba Abdul For
Chap-1: Introduction to Object-oriented
Programming 28 BBC-2 – MUBS
END OF CHAPTER
QUESTIONS
 Question – 1: Using an illustrative diagram,
distinguish between POP and OOP approaches to
programming.
 Question – 2: Discuss the distinguishing features of
POP and OOP approaches to programming.
 Question – 3: Using an appropriate diagram,
distinguish between step-wise refinement and bottom-
up program design. Give reasons to justify why you
would use each of the above design methods.
 Question – 4: Examine the limitations of POP
approach and how they paved way for the emergence
of OOP approach.
© 2023 Prepared By Ddamba Abdul For
Chap-1: Introduction to Object-oriented
Programming 29 BBC-2 – MUBS
END OF CHAPTER
QUESTIONS
 Question – 5: Discuss how the development of OOP
approach sought to solve problems associated with
POP approach.
 Question – 6: Using illustrations and appropriate
diagrams, explain all the concepts of OOP technique.
 Question – 7: Using any given examples, explain
what is meant with an object and state all the main
differences that exist between objects and classes.
 Question – 8: Using real-world practical examples,
discuss the concepts of abstraction, encapsulation,
inheritance and polymorphism as used in OOP
technique
© 2023 Prepared By Ddamba Abdul For
Chap-1: Introduction to Object-oriented
Programming 30 BBC-2 – MUBS

You might also like