Chapter 1 Introduction To Object Oriented Programming OOP PDF
Chapter 1 Introduction To Object Oriented Programming OOP PDF
Introduction to Object-Oriented
Programming (OOP)
Lecture by Ts. Hanis Basira Abu Hasan
27th September 2022
2
Sub-Chapter 1.1
3
Learning Contents Sub-Chapter 1.1
5
Various Programming Techniques
Unstructured Programming
4
6
Various Programming Techniques
Unstructured Programming
10
Various Programming Techniques
Object Oriented Programming
7
• Object oriented programming languages are various but the most popular
ones are class-based, meaning that objects are instances of classes, which
also determine their types.
11
Various Programming Techniques
Object Oriented Programming
7
12
Unstructured Programming Vs Procedural
Programming Vs Object Oriented Programming
9
• Based on ‘objects’.
Object-
• Gives more preference to data rather than logic
Oriented • Bottom up approach
13
Unstructured Programming Vs Procedural
Programming Vs Object Oriented Programming
10
Source: http://www.differencebetween.info/difference-between-procedural-structural-and-object-
oriented- programming-languages
14
Object Oriented
Approach
15
Object Oriented Approach
OOP Concept
• Object means a real word entity such as pen, chair, table etc.
16
Object Oriented Approach
OOP Concept
17
Object Oriented Approach
History of OOP
SIMULA was the first object language. As its name suggests it was used to create
simulations.
In the early 1990s a group at Sun led by James Gosling developed a simpler version of
C++ called Java that was meant to be a programming language for video-on-demand
applications. The language has gained widespread popularity as the Internet has
boomed
18
Benefit of Using Object Oriented
Approach
19
Benefit of Using Object Oriented Approach
Advantages of OOP
21
Terms Used
Object Oriented Analysis And Design (OOAD)
23
Terms Used
Object Oriented Analysis And Design (OOAD)
• The following represents the terms used in Object Oriented
Analysis and Design (OOAD)
24
Sub-Chapter 1.2
25
Learning Contents Sub-Chapter 1.2
26
Object Oriented
Languages
27
Object Oriented Languages
Examples
28
Object Oriented Languages
Top OOP Languages To Follow In 2020
1 Python
2 Java
3 C#
4 Ruby
5 C++
29
Object, Attribute And Behaviour
30
Object, Attribute And Behaviour
Object
BankAccount
32
Object Oriented Concepts And
Terminologies
33
Object Oriented Concepts And Terminologies
Basic Terminologies of OOP
Classes
Polymorphism Object
OOP
Inheritance Encapsulation
Data
Abstraction
34
Object Oriented Concepts And Terminologies
Objects
• Look around right now and you'll find many examples of real-
world objects: your dog, your desk, your television set, your
bicycle.
35
Object Oriented Concepts And Terminologies
Objects
• Bicycles have
– state (current gear,
current pedal cadence,
current speed) and
– behavior (changing
gear, changing pedal
cadence, applying
brakes)
36
Object Oriented Concepts And Terminologies
Objects
• An object
– stores its state in fields (variables in some programming
languages) and
– exposes its behavior through methods (functions in some
programming languages).
37
Object Oriented Concepts And Terminologies
Classes
• Class is a blueprint or prototype from which objects are created.
• For example:
– There may be thousands of other bicycles in existence, all of
the same made and model. Each bicycle was built from the
same set of blueprints and therefore contains the same
components.
Class Bicycle
State / Attribute
color
speed
gear = 1
Behavior / Method
setColor
changeGear
speedup
printStates
39
Object Oriented Concepts And Terminologies
Classes – Example Bicycle
Bicycle.java Output
BicycleDemo.java
40
Object Oriented Concepts And Terminologies
Class and Object
41
Object Oriented Concepts And Terminologies
Encapsulation
• Binding (or wrapping) code and data together into a single unit
is known as encapsulation.
42
Object Oriented Concepts And Terminologies
Encapsulation - Example Encapsulation
Encapsulation.java Output
EncapsulationTest.java
43
Object Oriented Concepts And Terminologies
Inheritance
• OOP allows classes to inherit commonly used state and
behavior from other classes.
44
Object Oriented Concepts And Terminologies
Inheritance
• Inheritance provides a powerful and natural mechanism for organizing
and structuring your software.
• For example: Mountain bikes, road bikes, and tandem bikes; all share
the characteristics of bicycles (current speed, current pedal cadence,
current gear).
• Yet each also defines additional features that make them different:
– Tandem bicycles have two seats and two sets of handlebars;
– Road bikes have drop handlebars;
– Mountain bikes have an additional chain ring, giving them a lower
gear ratio.
45
Object Oriented Concepts And Terminologies
Inheritance
• The syntax for creating a subclass
is simple. At the beginning of
your class declaration, use the
extends keyword, followed by
the name of the class to inherit
from:
https://docs.oracle.com/javase/tutorial/java/concepts/inheritance.html 46
Object Oriented Concepts And Terminologies
Inheritance
• Another example:
– Classes can be organized into hierarchies.
Account
Charge Bank
Account Account
Savings Checking
Account Account
47
Object Oriented Concepts And Terminologies
Polymorphism
48
Object Oriented Concepts And Terminologies
Polymorphism - Example Bicycle
Bicycle.java
49
Object Oriented Concepts And Terminologies
Polymorphism - Example Bicycle
Bicycle.java
50
Object Oriented Concepts And Terminologies
Polymorphism - Example Bicycle
MountainBike.java
51
Object Oriented Concepts And Terminologies
Polymorphism - Example Bicycle
RoadBike.java
52
Object Oriented Concepts And Terminologies
Polymorphism - Example Bicycle
TestBikes.java
Output
53
Object Oriented Concepts And Terminologies
Data Abstraction
54
Object Oriented Concepts And Terminologies
Data Abstraction – Example Demo1
Demo2.java
Output
55
Object Oriented Concepts And Terminologies
Distinguish Between Abstraction & Encapsulation
• Abstraction represent taking out the behavior from How exactly its
implemented, example of abstraction is interface.
57
~THE END~
End Of Chapter 1
58