You are on page 1of 20

OBJECT-ORIENTED PROGRAMMING

Benjamin Babić

Zagreb University of Applied Sciences - 28.3.2021.


INTRODUCTION
PROCEDURAL PROGRAMMING

 Before object-oriented programming we had


„procedural programming”

 Divides programming into a set of functions and


variables that operate on the data

 Plain simple, straightforward

 Problems => „Spaghetti Code”


 Interdependence

2
O B J E C T- O R I E N T E D
PROGARMMING
P R O G R A M M I N G PA R A D I G M

 Combining group of related variables and functions into a


unit => object Real World => Code
 Variables = Properties of an object
 Methods = Functions of an object
 Example: Calculator

PROPERTIES METHODS

Dimensions Addition
Model Division
Colour Exponentiation
Weight Square Root
Battery Type Trigonometric functions
3
PILLARS OF
OBJECT-
ORIENTED
PROGARMMING
CORE CONCEPT

4
ENCAPSULATIO
N

5
E N C A P S U L AT I O N

 DEFINITION: bundling of data, along with the methods that operate on that data, into a single unit.

 Mechanism of restricting the direct access to some components of an object

Information hiding

 Getter: retrieve the value of a specific variable within a class.


 Setter: set or update the value of a specific variable within a class.
 Access modifiers: define the visibility and accessibility of classes, their data and methods
 Implementation => protecting sensitive data

6
The best functions are those with no
parameters !

ROBERT C. MARTIN
ABSTRACTION

9
A B ST R AC T I O N

 DEFINITION: Showing essential attributes to the user


and hiding unnecessary information

 Example: Computer Monitor / DVD

 Only a few buttons

 How it works? ==> Hidden Complexity

 Simple interface, reduce the impact of change

10
11
INHERITANCE

12
I N H E R I TA N C E PARENT CLASS

 DEFINITION: Mechanism that helps to eliminate


redundant code while increasing code reusability

 Subclass = Extended Class = Child Class CHILD CLASS CHILD CLASS

 Super Class = Base Class = Parent Class

 Example: Car

PROPERTIES METHODS

Color Start
Fuel Accelerate
Model Brake
Transmision Type Gear Shift
Number of doors/seats Directional signals

13
14
POLYMORPHISM

15
P O LY M O R P H I S M MOVE CLASS

 Poly = Many, Morph = Form => existing in many forms


SNAIL KANGAROO
 DEFINITION: The ability to create a property, a function or an
object that has more than one realization.
DOG FISH
 Concept: Different classes can be used with the same interface

 Two types of Polymorphism:

- Runtime

- Compile Time

16
17
BENEFITS
E N C A P S U L AT I O N
 Reduce complexity, limiting vulnerabilities, data protection

ABSTRACTION
 Show essential attributes, isolate impact of changes

I N H E R I TA N C E
 Eliminate redundant code, code reusability

P O LY M O R P H I S M
 Enforcing simplicity, saving time, extandable codes, easily
maintained applications

18
QUESTIONS?

Benjamin Babić benjamin.babic@tvz.hr


L I T E R AT U R E

 https://www.sumologic.com/glossary/encapsulation/
 https://stackify.com/oop-concept-polymorphism/
 https://en.wikipedia.org/wiki/Object-oriented_programming#Encapsulation
 https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)
 https://www.youtube.com/watch?v=1ONhXmQuWP8
 https://en.wikipedia.org/wiki/Polymorphism_(computer_science)
 https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)
 https://en.wikipedia.org/wiki/Abstraction_(computer_science)
 https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
 https://www.nerd.vision/post/polymorphism-encapsulation-data-abstraction-and-inheritance-in-object-ori
ented-programming

You might also like