SlideShare a Scribd company logo
1 of 30
Object Oriented
Programming
Course Instructor: Dr Mrs I. Botchway Essandoh
Computer Science & Engineering Department
University of Mines & Technology (UMaT) 1
Introduction
The Concept of Programming
• What is Programming?
Do I need to be good in maths?
What about logic?
• What is Computer Programming?
Designing and building executable computer programs
Object Oriented Programming 2
Computer Programs
do real world things
on their own.
Why do we need to learn about Object-Oriented Programming?
• Object-Oriented Programming was developed because
limitations were discovered in the earlier programming
approaches.
Object Oriented Programming 3
Introduction
Evolution of Programming Techniques
• Procedural Programming (PP);
• Structured Programming; and
• Object Oriented Programming.
• Views a program as a series of steps (procedures) to be
carried out;
 Uses a list of instructions; and
 Takes inputs and returns outputs.
 E.g. C, FORTRAN, Cobol, Pascal
• Division into functions
Each function has a clearly defined purpose and a clearly
defined interface to the other functions in the program.
The idea of breaking a program into functions can further be
extended by grouping a number of functions together into a
larger entity called a module.
Object Oriented Programming 4
Procedural Programming
Object Oriented Programming 5
Procedural Programming
Main Program
Function 1 Function 3
Function 2
Function 4 Function 5
Function 8
Function 7
Function 6
• In multi-function programs, important data items are placed
as global data so that they may be accessed by all functions.
• Each function may as well have its own local data.
Object Oriented Programming 6
Procedural Programming
Global
Data
Global
Data
Global
Data
Function 1 Function 2 Function 3 Function 4
Problems with Procedural Languages
• Since every function has complete access to the global data,
a new programmer can corrupt the data accidentally;
• Cannot cope with very large project sizes (Complexity) since
it is difficult to identify the data used by a specific function;
• Difficult to modify and maintain;
• Codes are often not reusable;
• We can access the data of one function from another, hence,
there is security unfriendliness due to code exposure; and
• Program codes become difficult to write when working with a
larger project.
Object Oriented Programming 7
Procedural Programming
Causes of Problems
• Unrestricted Access to Data
 Global data/variable is allowed
 Access to data by multiple functions means many connections
between functions
 Programs become more difficult to understand
• Poor Modeling of Real World Things
 Real world things are integral collections of data
(Attributes/properties/features) and functions (Behaviour)
 e.g. a car: has data (make, model etc.) and functions (acceleration)
 Procedural languages do not tie up data with functions
Object Oriented Programming 8
Procedural Programming
Characteristics:
• Large programs are divided into smaller programs known as
functions.
• Most of the functions share global data.
• Data can move openly around the system from function to
function.
• Employs the top-down approach in program design.
The top-down programming approach
This is the process of breaking tasks into component parts
called modules and the subdivide each component module
until the lowest level of detail has been reached.
Object Oriented Programming 9
Procedural Programming
• Structured Programming can be defined as a programming
approach in which the program is made as a single
structure.
• It means that the code will execute the instruction one after
the other.
• It doesn’t support the possibility of jumping from one
instruction to some other with the help of any statement like
GOTO, etc.
• Therefore, the instructions in this approach will be executed
in a serial and structured manner.
• Organizes Procedural Programming into functions and
modules.
• E.g. Pascal, Cobol, C
Object Oriented Programming 10
Structured Programming
Object Oriented Language
• OOP was introduced to overcome the
flaws in procedural programming such
as reusability and maintainability.
• Views a program as a group of objects
that have certain properties and can
perform certain functions.
• E.g. C++, Java, C#, Python
Object Oriented Programming 11
Object-Oriented Programming
Object:
John
• Clearer, more reliable, more easily maintained programs;
• More effective way of coping with program complexity;
• It basically supports encapsulation, abstraction, inheritance
and polymorphism; and
• It also includes data hiding features therefore it is more
secure.
Object Oriented Programming 12
Goal of OOP
• The fundamental idea is to combine into a single unit both
data/variable (features) and functions that operate on the
data.
• Such a unit is called an “Object”.
• In OOP, problems are divided into the number of entities
(objects) and then builds data and functions around these
entities (objects).
• It ties the data more closely to the functions that operate on
it and protects it from accidental modification from outside
functions.
Object Oriented Programming 13
The Object-oriented Approach
• Data of an object can be accessed only by the functions
associated with that object.
• Communication of objects is done through functions.
• Data and its function are said to be encapsulated into a
single entity called a class.
• Data encapsulation and data hiding are key elements of
object-oriented languages.
Object Oriented Programming 14
The Object-oriented Approach
• If you want to modify data in an object, you know exactly
what functions interact with it (i.e. the member functions of
the object).
• This simplifies writing, debugging, and maintaining the
programs.
Object Oriented Programming 15
The Object-oriented Approach
Object Oriented Programming 16
Attributes
Methods
Methods
Attributes
Methods
Methods
Attributes
Methods
Methods
object
object
The Object-oriented Paradigm
Characteristics:
• Programs are divided into entities known as objects.
• Data is hidden and cannot be accessed by external functions.
• Objects communicate with each other through functions.
• New data and functions can be easily added whenever
necessary.
• Employs the bottom up approach in program design.
Object Oriented Programming 17
Object-Oriented Programming
OOP is suitable when
you want to group
attributes and methods
together into a handy
packet of functionality
Procedural OOP
The program is divided into
small parts called functions.
The program is divided into
small parts called objects.
There is no use of access
modifiers.
Uses access modifiers like
private, public, protected, etc.
Does not have any proper way
of hiding data so it is less
secure.
Provides data hiding so it is
more secure.
Does not have the concept of
inheritance.
Supports inheritance
Absent of code reusability It offers code reusability by
using the feature of inheritance.
Object Oriented Programming 18
Procedural Vs. OOP
• The structure of object-oriented programming include the
following:
Object Oriented Programming 19
Structure of OOP Languages
• The Object-oriented approach relies on a number of concepts
that define object-oriented languages.
Object Oriented Programming 20
Concepts of OOP Languages
OOP
Concepts
Class
Objects
Abstraction
Encapsulation
Inheritance
Polymorphism
Dynamic
Binding
Message
Passing
Object Oriented Programming 21
Classes
Class
Data/Variables
Properties/
Features
Functions
Methods/
Behavior
Object
• A collection of data and features encapsulated in a single
unit.
• A class is a user-defined data type that we can use in our
program, and it works as a blueprint for creating objects but
it doesn’t actually provide any real content itself.
• The Dog( ) class may specify that the name and age are
necessary for defining a dog, but it will not actually state
what a specific dog’s name or age is.
Object Oriented Programming 22
Classes/ Objects
think of a class as an idea for how
something should be defined
• Classes enable the creation of specific instances of the
system being modeled (Object).
• Attributes and methods are basically variables and
functions that belongs to the class. These are often referred
to as class members.
Creating a Class in Python
• Use the class keyword, followed by the class name and a
colon
Syntax
class ClassName:
# class definition
Object Oriented Programming 23
Classes/ Objects
• When a class is defined, only the specification for the object
is defined; no memory or storage is allocated. To use the data
and access functions defined in the class, we need to create
objects.
• An object is created from a class. It is an instance of a class
with actual values.
Object Oriented Programming 24
Objects
• An object is a software item that contains variables and
methods.
• They may represent a person, a place, a bank account, or
any item that a program must handle.
• When a program is executed, the objects interact by sending
messages to one another.
• Objects have two components:
• Data (attributes)
• Behaviors (functions or methods)
Object Oriented Programming 25
Objects
Instantiating Object
• To create an object of a class, type the class name, followed
by ( ). Assign the class name to the object name.
Syntax
class ClassName:
pass
objectName = ClassName()
Access Class Attributes Using Objects
• The attributes of a class can be accessed using the dot (.)
notation on the object of the class.
Object Oriented Programming 26
Objects
Object Oriented Programming 27
Example 1: An Empty Class
Object Oriented Programming
class Student:
pass
stud1 = Student()
stud1.name='Amina'
stud1.age = 20
stud1.dpt = 'Electrical'
stud1.hostel = 'Gold Refinery Hall'
print(f'Name:
{stud1.name}nAge:{stud1.age}nDepartment:{stud1.dpt}
nHostel:{stud1.hostel}n')
27
Object Oriented Programming 28
Example 2: Multiple Objects
Object Oriented Programming
class Student:
pass
stud1 = Student()
stud2 = Student()
stud1.name='Amina'
stud1.age = 20
stud1.dpt = 'Electrical'
stud1.hostel = 'Gold Refinery Hall'
stud2.name='Abena'
stud2.age = 19
stud2.dpt = 'Electrical'
stud2.hostel = 'KT Hall'
print(f'Name:
{stud1.name}nAge:{stud1.age}nDepartment:{stud1.dpt}nHostel:
{stud1.hostel}n')
print(f'Name:
{stud2.name}nAge:{stud2.age}nDepartment:{stud2.dpt}nHostel:
{stud2.hostel}')
28
Example 3: Class with Attributes
class Cars:
name = ''
make = ''
model = ''
year = 0
car1 = Cars() # Creating first object
car1.name='Toyota'
car1.make = 'Corolla'
car1.model = 'LE'
car1.year = 2016
car2 = Cars() # Creating second object
car2.name='Honda'
car2.make = 'Civic'
car2.model = 'Hybrid'
car2.year = 2018
car3 = Cars() # Creating third object
car3.name='Mercedes Benz'
car3.make = 'C class'
car3.model = '300'
car3.year = 2000
print(f"The vehicle name is
{car1.name} and it's make is
{car1.make}. nThe model is
{car1.model} and it's year
is {car1.year}n")
print(f"The vehicle name is
{car2.name} and it's make is
{car2.make}. nThe model is
{car2.model} and it's year
is {car2.year}n")
print(f"The vehicle name is
{car3.name} and it's make is
{car3.make}. nThe model is
{car3.model} and it's year
is {car3.year}")
Object Oriented Programming 30
End of Lecture 2
Object Oriented Programming

More Related Content

What's hot (20)

Sending emails through PHP
Sending emails through PHPSending emails through PHP
Sending emails through PHP
 
Xml ppt
Xml pptXml ppt
Xml ppt
 
CS8651 Internet Programming - Basics of HTML, HTML5, CSS
CS8651   Internet Programming - Basics of HTML, HTML5, CSSCS8651   Internet Programming - Basics of HTML, HTML5, CSS
CS8651 Internet Programming - Basics of HTML, HTML5, CSS
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Json
JsonJson
Json
 
Xml
XmlXml
Xml
 
Web development using html 5
Web development using html 5Web development using html 5
Web development using html 5
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Uml class Diagram
Uml class DiagramUml class Diagram
Uml class Diagram
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Web servers
Web serversWeb servers
Web servers
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
html5.ppt
html5.ppthtml5.ppt
html5.ppt
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
CSS notes
CSS notesCSS notes
CSS notes
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 

Similar to OOP-1.pptx

1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.pptsagarjsicg
 
Object oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oopObject oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oopVaibhav Khanna
 
Object Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer ScienceObject Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer ScienceShailendraPandey96
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTnikshaikh786
 
Lesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptxLesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptxLuiFlor
 
itft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in javaitft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in javaAtul Sehdev
 
Unit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxUnit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxshashiden1
 
16613874-Object-Oriented-Programming-Presentation.ppt
16613874-Object-Oriented-Programming-Presentation.ppt16613874-Object-Oriented-Programming-Presentation.ppt
16613874-Object-Oriented-Programming-Presentation.pptvsdfg
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)Jay Patel
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptxYashKoli22
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - IntroductionMadishetty Prathibha
 

Similar to OOP-1.pptx (20)

Principles of OOPs.pptx
Principles of OOPs.pptxPrinciples of OOPs.pptx
Principles of OOPs.pptx
 
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 
Object oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oopObject oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oop
 
Object Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer ScienceObject Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer Science
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 
Lesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptxLesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptx
 
itft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in javaitft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in java
 
Unit v(dsc++)
Unit v(dsc++)Unit v(dsc++)
Unit v(dsc++)
 
C++ chapter 1
C++ chapter 1C++ chapter 1
C++ chapter 1
 
Unit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxUnit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptx
 
16613874-Object-Oriented-Programming-Presentation.ppt
16613874-Object-Oriented-Programming-Presentation.ppt16613874-Object-Oriented-Programming-Presentation.ppt
16613874-Object-Oriented-Programming-Presentation.ppt
 
chapter-6-oops.pdf
chapter-6-oops.pdfchapter-6-oops.pdf
chapter-6-oops.pdf
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptx
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
 
[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP
 

Recently uploaded

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 

Recently uploaded (20)

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 

OOP-1.pptx

  • 1. Object Oriented Programming Course Instructor: Dr Mrs I. Botchway Essandoh Computer Science & Engineering Department University of Mines & Technology (UMaT) 1
  • 2. Introduction The Concept of Programming • What is Programming? Do I need to be good in maths? What about logic? • What is Computer Programming? Designing and building executable computer programs Object Oriented Programming 2 Computer Programs do real world things on their own.
  • 3. Why do we need to learn about Object-Oriented Programming? • Object-Oriented Programming was developed because limitations were discovered in the earlier programming approaches. Object Oriented Programming 3 Introduction Evolution of Programming Techniques • Procedural Programming (PP); • Structured Programming; and • Object Oriented Programming.
  • 4. • Views a program as a series of steps (procedures) to be carried out;  Uses a list of instructions; and  Takes inputs and returns outputs.  E.g. C, FORTRAN, Cobol, Pascal • Division into functions Each function has a clearly defined purpose and a clearly defined interface to the other functions in the program. The idea of breaking a program into functions can further be extended by grouping a number of functions together into a larger entity called a module. Object Oriented Programming 4 Procedural Programming
  • 5. Object Oriented Programming 5 Procedural Programming Main Program Function 1 Function 3 Function 2 Function 4 Function 5 Function 8 Function 7 Function 6
  • 6. • In multi-function programs, important data items are placed as global data so that they may be accessed by all functions. • Each function may as well have its own local data. Object Oriented Programming 6 Procedural Programming Global Data Global Data Global Data Function 1 Function 2 Function 3 Function 4
  • 7. Problems with Procedural Languages • Since every function has complete access to the global data, a new programmer can corrupt the data accidentally; • Cannot cope with very large project sizes (Complexity) since it is difficult to identify the data used by a specific function; • Difficult to modify and maintain; • Codes are often not reusable; • We can access the data of one function from another, hence, there is security unfriendliness due to code exposure; and • Program codes become difficult to write when working with a larger project. Object Oriented Programming 7 Procedural Programming
  • 8. Causes of Problems • Unrestricted Access to Data  Global data/variable is allowed  Access to data by multiple functions means many connections between functions  Programs become more difficult to understand • Poor Modeling of Real World Things  Real world things are integral collections of data (Attributes/properties/features) and functions (Behaviour)  e.g. a car: has data (make, model etc.) and functions (acceleration)  Procedural languages do not tie up data with functions Object Oriented Programming 8 Procedural Programming
  • 9. Characteristics: • Large programs are divided into smaller programs known as functions. • Most of the functions share global data. • Data can move openly around the system from function to function. • Employs the top-down approach in program design. The top-down programming approach This is the process of breaking tasks into component parts called modules and the subdivide each component module until the lowest level of detail has been reached. Object Oriented Programming 9 Procedural Programming
  • 10. • Structured Programming can be defined as a programming approach in which the program is made as a single structure. • It means that the code will execute the instruction one after the other. • It doesn’t support the possibility of jumping from one instruction to some other with the help of any statement like GOTO, etc. • Therefore, the instructions in this approach will be executed in a serial and structured manner. • Organizes Procedural Programming into functions and modules. • E.g. Pascal, Cobol, C Object Oriented Programming 10 Structured Programming
  • 11. Object Oriented Language • OOP was introduced to overcome the flaws in procedural programming such as reusability and maintainability. • Views a program as a group of objects that have certain properties and can perform certain functions. • E.g. C++, Java, C#, Python Object Oriented Programming 11 Object-Oriented Programming Object: John
  • 12. • Clearer, more reliable, more easily maintained programs; • More effective way of coping with program complexity; • It basically supports encapsulation, abstraction, inheritance and polymorphism; and • It also includes data hiding features therefore it is more secure. Object Oriented Programming 12 Goal of OOP
  • 13. • The fundamental idea is to combine into a single unit both data/variable (features) and functions that operate on the data. • Such a unit is called an “Object”. • In OOP, problems are divided into the number of entities (objects) and then builds data and functions around these entities (objects). • It ties the data more closely to the functions that operate on it and protects it from accidental modification from outside functions. Object Oriented Programming 13 The Object-oriented Approach
  • 14. • Data of an object can be accessed only by the functions associated with that object. • Communication of objects is done through functions. • Data and its function are said to be encapsulated into a single entity called a class. • Data encapsulation and data hiding are key elements of object-oriented languages. Object Oriented Programming 14 The Object-oriented Approach
  • 15. • If you want to modify data in an object, you know exactly what functions interact with it (i.e. the member functions of the object). • This simplifies writing, debugging, and maintaining the programs. Object Oriented Programming 15 The Object-oriented Approach
  • 16. Object Oriented Programming 16 Attributes Methods Methods Attributes Methods Methods Attributes Methods Methods object object The Object-oriented Paradigm
  • 17. Characteristics: • Programs are divided into entities known as objects. • Data is hidden and cannot be accessed by external functions. • Objects communicate with each other through functions. • New data and functions can be easily added whenever necessary. • Employs the bottom up approach in program design. Object Oriented Programming 17 Object-Oriented Programming OOP is suitable when you want to group attributes and methods together into a handy packet of functionality
  • 18. Procedural OOP The program is divided into small parts called functions. The program is divided into small parts called objects. There is no use of access modifiers. Uses access modifiers like private, public, protected, etc. Does not have any proper way of hiding data so it is less secure. Provides data hiding so it is more secure. Does not have the concept of inheritance. Supports inheritance Absent of code reusability It offers code reusability by using the feature of inheritance. Object Oriented Programming 18 Procedural Vs. OOP
  • 19. • The structure of object-oriented programming include the following: Object Oriented Programming 19 Structure of OOP Languages
  • 20. • The Object-oriented approach relies on a number of concepts that define object-oriented languages. Object Oriented Programming 20 Concepts of OOP Languages OOP Concepts Class Objects Abstraction Encapsulation Inheritance Polymorphism Dynamic Binding Message Passing
  • 21. Object Oriented Programming 21 Classes Class Data/Variables Properties/ Features Functions Methods/ Behavior Object
  • 22. • A collection of data and features encapsulated in a single unit. • A class is a user-defined data type that we can use in our program, and it works as a blueprint for creating objects but it doesn’t actually provide any real content itself. • The Dog( ) class may specify that the name and age are necessary for defining a dog, but it will not actually state what a specific dog’s name or age is. Object Oriented Programming 22 Classes/ Objects think of a class as an idea for how something should be defined
  • 23. • Classes enable the creation of specific instances of the system being modeled (Object). • Attributes and methods are basically variables and functions that belongs to the class. These are often referred to as class members. Creating a Class in Python • Use the class keyword, followed by the class name and a colon Syntax class ClassName: # class definition Object Oriented Programming 23 Classes/ Objects
  • 24. • When a class is defined, only the specification for the object is defined; no memory or storage is allocated. To use the data and access functions defined in the class, we need to create objects. • An object is created from a class. It is an instance of a class with actual values. Object Oriented Programming 24 Objects
  • 25. • An object is a software item that contains variables and methods. • They may represent a person, a place, a bank account, or any item that a program must handle. • When a program is executed, the objects interact by sending messages to one another. • Objects have two components: • Data (attributes) • Behaviors (functions or methods) Object Oriented Programming 25 Objects
  • 26. Instantiating Object • To create an object of a class, type the class name, followed by ( ). Assign the class name to the object name. Syntax class ClassName: pass objectName = ClassName() Access Class Attributes Using Objects • The attributes of a class can be accessed using the dot (.) notation on the object of the class. Object Oriented Programming 26 Objects
  • 27. Object Oriented Programming 27 Example 1: An Empty Class Object Oriented Programming class Student: pass stud1 = Student() stud1.name='Amina' stud1.age = 20 stud1.dpt = 'Electrical' stud1.hostel = 'Gold Refinery Hall' print(f'Name: {stud1.name}nAge:{stud1.age}nDepartment:{stud1.dpt} nHostel:{stud1.hostel}n') 27
  • 28. Object Oriented Programming 28 Example 2: Multiple Objects Object Oriented Programming class Student: pass stud1 = Student() stud2 = Student() stud1.name='Amina' stud1.age = 20 stud1.dpt = 'Electrical' stud1.hostel = 'Gold Refinery Hall' stud2.name='Abena' stud2.age = 19 stud2.dpt = 'Electrical' stud2.hostel = 'KT Hall' print(f'Name: {stud1.name}nAge:{stud1.age}nDepartment:{stud1.dpt}nHostel: {stud1.hostel}n') print(f'Name: {stud2.name}nAge:{stud2.age}nDepartment:{stud2.dpt}nHostel: {stud2.hostel}') 28
  • 29. Example 3: Class with Attributes class Cars: name = '' make = '' model = '' year = 0 car1 = Cars() # Creating first object car1.name='Toyota' car1.make = 'Corolla' car1.model = 'LE' car1.year = 2016 car2 = Cars() # Creating second object car2.name='Honda' car2.make = 'Civic' car2.model = 'Hybrid' car2.year = 2018 car3 = Cars() # Creating third object car3.name='Mercedes Benz' car3.make = 'C class' car3.model = '300' car3.year = 2000 print(f"The vehicle name is {car1.name} and it's make is {car1.make}. nThe model is {car1.model} and it's year is {car1.year}n") print(f"The vehicle name is {car2.name} and it's make is {car2.make}. nThe model is {car2.model} and it's year is {car2.year}n") print(f"The vehicle name is {car3.name} and it's make is {car3.make}. nThe model is {car3.model} and it's year is {car3.year}")
  • 30. Object Oriented Programming 30 End of Lecture 2 Object Oriented Programming