SlideShare a Scribd company logo
Introduction to
OOP Concepts
BY: SAMUEL ANSONG
Pre-Requisites
• Familiarity with functions and types
• Basic understanding of a class
• Has an overall Introduction to programming
• We will be using C# for code samples
Pre-Requisite Check
1. Write a simple function to add all numbers in the array below
int [] array = new int[] {2,4,5,6,7,8,8,9,0,10,5,7}
Hint
<visibility> <return type> <name>(<parameters>)
{
<function code>
}
You can logon Here -> C# Online Compiler | .NET Fiddle (dotnetfiddle.net) and complete your
code.
Answer and Modification
1. Overload the function to take 3 numbers
2. Overload the method to take any amount of numbers
3. Change the function into a lambda format
Structure
Procedural Oriented Programming Overview
Limitations of POP
Object Oriented Programming Overview
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
Core Components
• Access Modifiers
• Static Class and Methods
Key Terms
Procedural Oriented Programming
• C , Pascal, FORTRAN, and similar languages are procedural languages
• Each Statement in the language tells the computer to do something
• Get some Input
• Add these numbers
• Divide by 4
• Display the number
A program in a procedural language is a list of
instructions
Divided Into Functions
• Procedural program is divided into functions
• Each function has clearly defined purpose and how it interfaces with other
functions in the program
• One can also further extend functions by grouping several functions together
into a larger entity called Modules .
Divided Into Functions
• In Multi-Function program important data items
are placed as Global so that they maybe
accessed by all functions
• Each function may also have its own local data
Limitations for POP
• Since all functions have accessed to the Global Variable , new functions
accidentally created can corrupt the data
• We can access the data of one function from other since there is no
protection
• In a large program it is difficult to trace what data is used by which function
• If new data is added , all the functions are to be modified to access this data
Object Oriented Programming
• OOP was introduced to overcome flaws in the procedural
approach to programming
• Such as lack of Reusability and Maintainability
• The Fundamental idea behind OOP is to combine into a
single unit both data and functions that operate on them.
• Such a unit is called an Object .
Objects?
In the real world, just about anything can be seen as an object:
car, dog, person, department, city, etc. These
have state and behavior. For example, a dog's state is its color,
breed and name; its behavior is the way it barks, runs or wags its
tail. Objects in OOP are quite similar
Example
Identify the Properties (State) and Behavior
(Methods) of Your Bicycle
Objects Continued…..
Object Oriented Programming
• In OOP, problem is divided into number of entities called objects
and then builds data and functions around these objects
• It ties the data more closely to the functions that operate it and
protects it from accidental modification from the outside functions
• Data of an object can only be accessed by the functions associated
with that object
• Communication of the objects done through functions.
Classes
• Classes are user-defined data types
• Objects are variables of a class
• Once a class has been defined, we can create any number of
objects from the Class
• A class thus can be said as a collection of similar objects of same
type.
Example
• Let us consider a software that involves renting cars.
• We can have a class and objects as below
Example
Let us consider a software that involves a zoo.
What are some of the classes and objects to be
created .
Answer
Core Concepts
Encapsulation
• Encapsulation is the first pillar or principle of object-oriented
programming
• In simple words, “Encapsulation is a process of binding data
members (variables, properties) and member
functions(methods) into a single unit”
• And a Class is the best example of encapsulation
• Data Hiding from all external Classes
Encapsulation
Encapsulation in Real Life
•Has prescription
•Does not have direct
contact to the medicines
Patient
•Has Access to the medicine
•Returns the right medicine
•Reduces risk of you getting
wrong medicine
Chemist •Can only be accessed by
chemists
•Several medicines available
for different treatments
Medicines
Encapsulation in OOP
•Has no direct access to
data in the medicine class
External
Classes
•Controls access and
manipulation of data in the
medicine class
•They are wrapped in the
class
Functions •Medicine Class
•Contains both member
functions and Variables
•Determines how accessible
the data is to outside world
Medicines
Encapsulation in OOP
So, Encapsulation means hiding the important features
of a class which has no usefulness being
exposed to outside of the class and exposing only the
necessary things of the class.
Abstraction
Abstraction is about describing something at a
conceptual level while leaving out the details.
example, we may talk about a vehicle without
being explicit if it's a ship or a car.
Example of Abstraction
When using the tv remote control, you do not
bother about how pressing a key in the remote
changes the channel on the TV. You Just know
that pressing the “+” volume button will increase
the volume.
Example of Abstraction
• A class can be abstract as well meaning , it can provide you
functions without their implementation
• For example, if our class was a remote control , it will give
us the method IncreaseVolume() without details of how It
will be done . Such a method is called an abstract method
Example of Abstraction
• You cannot instantiate this class
Animal myObj = new Animal(); // Will generate an
error
• You can only Inherit this class
Inheritance
• The mechanism of deriving a new class from an old class is called
inheritance or derivation
• The Old class is known as base class while new class is known as
derived class or sub class
• Inheritance is the most powerful feature of OOP.
• Gives the sub class access to methods of based class
Example
If a child is as Tall as his dad and Fair as his mom
, we usually say the child has inherited these
features from his father and mother.
Example
using System;
namespace MyApplication
{
class Vehicle // Base class
{
public string brand = "Ford"; // Vehicle field
public void honk() // Vehicle method
{
Console.WriteLine("Tuut, tuut!");
}
}
}
• The Base class here is Vehicle
• It has Properties (Brand) and an implemented
Method honk
Example
using System;
namespace MyApplication
{
class Car : Vehicle // Derived class
{
public string modelName = "Mustang"; // Car field
}
}
• The Base class here is Vehicle
• The Car class is inheriting the vehicle class and thus
Will have access to the honk method in the Vehicle class.
• Inheritance is shown by the “:” sign . Colon.
Example Code Snippet
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
// Create a myCar object
Car myCar = new Car();
// Call the honk() method (From the Vehicle class) on the myCar object
myCar.honk();
// Display the value of the brand field (from the Vehicle class) and the value of the modelName from the Car class
Console.WriteLine(myCar.brand + " " + myCar.modelName);
}
}
}
Inheritance
• Through Effective use of inheritance , you can save a lot of time in your
programming and reduces errors
• This will also increase the quality of the work and productivity
Polymorphism
• Polymorphism means "many forms", and it occurs
when we have many classes that are related to each
other by inheritance
• Inheritance lets us inherit fields and methods from
another class. Polymorphism uses those methods
to perform different tasks. This allows us to perform
a single action in different ways.
Example
For example, think of a base class called Animal that
has a method called animalSound(). Derived classes of
Animals could be Pigs, Cats, Dogs, Birds - And they
also have their own implementation of an animal
sound (the pig oinks, and the cat meows, etc.):
Example
class Animal // Base class (parent)
{
public void animalSound()
{
Console.WriteLine("The animal makes a sound");
}
}
class Pig : Animal // Derived class (child)
{
public void animalSound()
{
Console.WriteLine("The pig says: wee wee");
}
}
Next Lecture
Object Oriented Programming Implementation
Building a Game with C#
Unity 3D and C#
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
Modelling our Game as OOP

More Related Content

PPTX
Solid principles
PPTX
Clean code: SOLID
KEY
Solid principles
KEY
SOLID Design Principles
PDF
SOLID Design Principles applied in Java
PDF
Jdbc connectivity in java
PPSX
Strings in Java
Solid principles
Clean code: SOLID
Solid principles
SOLID Design Principles
SOLID Design Principles applied in Java
Jdbc connectivity in java
Strings in Java

What's hot (20)

PPT
Object-Oriented Programming Concepts
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Data Types, Variables, and Operators
PPT
SOLID Design Principles
PPTX
SOLID principles
PPTX
SOLID Principles
PPSX
Arrays in Java
PPTX
OOPS In JAVA.pptx
PPTX
SOLID & IoC Principles
PPTX
Solid principles
PPTX
Design principles - SOLID
PPTX
Chapter 3 servlet & jsp
PPTX
The Single Responsibility Principle
PDF
NodeJS for Beginner
PDF
Introduction to Design Pattern
PPTX
SOLID, DRY, SLAP design principles
PPT
PHP - Introduction to Object Oriented Programming with PHP
PPT
Advanced Javascript
PPTX
Java Beans
PPTX
Javascript operators
Object-Oriented Programming Concepts
Basic Concepts of OOPs (Object Oriented Programming in Java)
Data Types, Variables, and Operators
SOLID Design Principles
SOLID principles
SOLID Principles
Arrays in Java
OOPS In JAVA.pptx
SOLID & IoC Principles
Solid principles
Design principles - SOLID
Chapter 3 servlet & jsp
The Single Responsibility Principle
NodeJS for Beginner
Introduction to Design Pattern
SOLID, DRY, SLAP design principles
PHP - Introduction to Object Oriented Programming with PHP
Advanced Javascript
Java Beans
Javascript operators
Ad

Similar to Object Oriented Programming (OOP) Introduction (20)

PDF
JAVA-PPT'S.pdf
PPTX
object oriented programing lecture 1
PPTX
Introduction to oop
PPTX
JAVA-PPT'S-complete-chrome.pptx
PPTX
JAVA-PPT'S.pptx
PDF
80410172053.pdf
PPTX
Fundamentals of OOP (Object Oriented Programming)
PDF
Cs2305 programming paradigms lecturer notes
PPTX
Introduction to OOP concepts
PPT
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
PPT
Md02 - Getting Started part-2
PPTX
oop.pptx
PPTX
Class and Objects in python programming.pptx
PPTX
Introduction to OOPs second year cse.pptx
PPT
the education purpose of software C++.ppt
PPTX
C++ first s lide
PPTX
UNIT - 1 Java Fundamentals, Basics of java
PPTX
Presentation 4th
PPTX
JAVA-PPT'S.pdf
object oriented programing lecture 1
Introduction to oop
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S.pptx
80410172053.pdf
Fundamentals of OOP (Object Oriented Programming)
Cs2305 programming paradigms lecturer notes
Introduction to OOP concepts
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
Md02 - Getting Started part-2
oop.pptx
Class and Objects in python programming.pptx
Introduction to OOPs second year cse.pptx
the education purpose of software C++.ppt
C++ first s lide
UNIT - 1 Java Fundamentals, Basics of java
Presentation 4th
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Big Data Technologies - Introduction.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The Rise and Fall of 3GPP – Time for a Sabbatical?
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25 Week I
sap open course for s4hana steps from ECC to s4
Big Data Technologies - Introduction.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

Object Oriented Programming (OOP) Introduction

  • 2. Pre-Requisites • Familiarity with functions and types • Basic understanding of a class • Has an overall Introduction to programming • We will be using C# for code samples
  • 3. Pre-Requisite Check 1. Write a simple function to add all numbers in the array below int [] array = new int[] {2,4,5,6,7,8,8,9,0,10,5,7} Hint <visibility> <return type> <name>(<parameters>) { <function code> } You can logon Here -> C# Online Compiler | .NET Fiddle (dotnetfiddle.net) and complete your code.
  • 4. Answer and Modification 1. Overload the function to take 3 numbers 2. Overload the method to take any amount of numbers 3. Change the function into a lambda format
  • 5. Structure Procedural Oriented Programming Overview Limitations of POP Object Oriented Programming Overview • Encapsulation • Inheritance • Polymorphism • Abstraction Core Components • Access Modifiers • Static Class and Methods Key Terms
  • 6. Procedural Oriented Programming • C , Pascal, FORTRAN, and similar languages are procedural languages • Each Statement in the language tells the computer to do something • Get some Input • Add these numbers • Divide by 4 • Display the number A program in a procedural language is a list of instructions
  • 7. Divided Into Functions • Procedural program is divided into functions • Each function has clearly defined purpose and how it interfaces with other functions in the program • One can also further extend functions by grouping several functions together into a larger entity called Modules .
  • 8. Divided Into Functions • In Multi-Function program important data items are placed as Global so that they maybe accessed by all functions • Each function may also have its own local data
  • 9. Limitations for POP • Since all functions have accessed to the Global Variable , new functions accidentally created can corrupt the data • We can access the data of one function from other since there is no protection • In a large program it is difficult to trace what data is used by which function • If new data is added , all the functions are to be modified to access this data
  • 10. Object Oriented Programming • OOP was introduced to overcome flaws in the procedural approach to programming • Such as lack of Reusability and Maintainability • The Fundamental idea behind OOP is to combine into a single unit both data and functions that operate on them. • Such a unit is called an Object .
  • 11. Objects? In the real world, just about anything can be seen as an object: car, dog, person, department, city, etc. These have state and behavior. For example, a dog's state is its color, breed and name; its behavior is the way it barks, runs or wags its tail. Objects in OOP are quite similar
  • 12. Example Identify the Properties (State) and Behavior (Methods) of Your Bicycle
  • 14. Object Oriented Programming • In OOP, problem is divided into number of entities called objects and then builds data and functions around these objects • It ties the data more closely to the functions that operate it and protects it from accidental modification from the outside functions • Data of an object can only be accessed by the functions associated with that object • Communication of the objects done through functions.
  • 15. Classes • Classes are user-defined data types • Objects are variables of a class • Once a class has been defined, we can create any number of objects from the Class • A class thus can be said as a collection of similar objects of same type.
  • 16. Example • Let us consider a software that involves renting cars. • We can have a class and objects as below
  • 17. Example Let us consider a software that involves a zoo. What are some of the classes and objects to be created .
  • 20. Encapsulation • Encapsulation is the first pillar or principle of object-oriented programming • In simple words, “Encapsulation is a process of binding data members (variables, properties) and member functions(methods) into a single unit” • And a Class is the best example of encapsulation • Data Hiding from all external Classes
  • 22. Encapsulation in Real Life •Has prescription •Does not have direct contact to the medicines Patient •Has Access to the medicine •Returns the right medicine •Reduces risk of you getting wrong medicine Chemist •Can only be accessed by chemists •Several medicines available for different treatments Medicines
  • 23. Encapsulation in OOP •Has no direct access to data in the medicine class External Classes •Controls access and manipulation of data in the medicine class •They are wrapped in the class Functions •Medicine Class •Contains both member functions and Variables •Determines how accessible the data is to outside world Medicines
  • 24. Encapsulation in OOP So, Encapsulation means hiding the important features of a class which has no usefulness being exposed to outside of the class and exposing only the necessary things of the class.
  • 25. Abstraction Abstraction is about describing something at a conceptual level while leaving out the details. example, we may talk about a vehicle without being explicit if it's a ship or a car.
  • 26. Example of Abstraction When using the tv remote control, you do not bother about how pressing a key in the remote changes the channel on the TV. You Just know that pressing the “+” volume button will increase the volume.
  • 27. Example of Abstraction • A class can be abstract as well meaning , it can provide you functions without their implementation • For example, if our class was a remote control , it will give us the method IncreaseVolume() without details of how It will be done . Such a method is called an abstract method
  • 28. Example of Abstraction • You cannot instantiate this class Animal myObj = new Animal(); // Will generate an error • You can only Inherit this class
  • 29. Inheritance • The mechanism of deriving a new class from an old class is called inheritance or derivation • The Old class is known as base class while new class is known as derived class or sub class • Inheritance is the most powerful feature of OOP. • Gives the sub class access to methods of based class
  • 30. Example If a child is as Tall as his dad and Fair as his mom , we usually say the child has inherited these features from his father and mother.
  • 31. Example using System; namespace MyApplication { class Vehicle // Base class { public string brand = "Ford"; // Vehicle field public void honk() // Vehicle method { Console.WriteLine("Tuut, tuut!"); } } } • The Base class here is Vehicle • It has Properties (Brand) and an implemented Method honk
  • 32. Example using System; namespace MyApplication { class Car : Vehicle // Derived class { public string modelName = "Mustang"; // Car field } } • The Base class here is Vehicle • The Car class is inheriting the vehicle class and thus Will have access to the honk method in the Vehicle class. • Inheritance is shown by the “:” sign . Colon.
  • 33. Example Code Snippet using System; namespace MyApplication { class Program { static void Main(string[] args) { // Create a myCar object Car myCar = new Car(); // Call the honk() method (From the Vehicle class) on the myCar object myCar.honk(); // Display the value of the brand field (from the Vehicle class) and the value of the modelName from the Car class Console.WriteLine(myCar.brand + " " + myCar.modelName); } } }
  • 34. Inheritance • Through Effective use of inheritance , you can save a lot of time in your programming and reduces errors • This will also increase the quality of the work and productivity
  • 35. Polymorphism • Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance • Inheritance lets us inherit fields and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.
  • 36. Example For example, think of a base class called Animal that has a method called animalSound(). Derived classes of Animals could be Pigs, Cats, Dogs, Birds - And they also have their own implementation of an animal sound (the pig oinks, and the cat meows, etc.):
  • 37. Example class Animal // Base class (parent) { public void animalSound() { Console.WriteLine("The animal makes a sound"); } } class Pig : Animal // Derived class (child) { public void animalSound() { Console.WriteLine("The pig says: wee wee"); } }
  • 38. Next Lecture Object Oriented Programming Implementation Building a Game with C# Unity 3D and C# • Encapsulation • Inheritance • Polymorphism • Abstraction Modelling our Game as OOP