SlideShare une entreprise Scribd logo
1  sur  19
Object-Oriented Programming

With JavaScript
• Object-oriented programming (OOP)
uses “objects”– data structures consisting
of datafields and methods and their
interactions to design applications and
computer programs
• Each object can be seen as a tiny machine
which is responsible for the set of task assign
to it.
• Today, many popular programming languages
(such as Java, JavaScript, C#, C++, Python, PHP
etc) support object-oriented
programming (OOP).
• JavaScript has strong object-oriented
programming capabilities. Although there is
differences in object-oriented capability of
javascript compared to other languages.
Terminology
• Class: Defines the characteristics of the
Object.
Constructor: A method called at the moment
of instantiation.
Object: An Instance of a Class.
Method: An Object capability as walk.
Property: An Object characteristic, such as
color.
Inheritance: A Class can inherit characteristics
from another Class.
• Encapsulation: A Class defines only the
characteristics of the Object, a method
defines only how the method executes.
Abstraction: The conjunction of complex
inheritance, methods, properties of an Object
must be able to simulate a reality model.
Polymorphism: Different Classes might define
the same method or property.
The Class in JavaScript
• Unlike Java, C++ etc., JavaScript does not
contains class statement. JavaScript is a
prototype-based language. JavaScript uses
functions as classes. Defining a class is as easy
as defining a function. In the example below
we define a new class called Car.
The Object
(Class Instance) in JavaScript
• For creating instances of any class i.e. objects
use new keyword. For example, in below code
snippet we created two instances of class Car.
Constructor
• Constructor is a method that is used to initiate
the properties of any class instance.
• Thus the constructor gets called when the
class is instantiated.
• As in JavaScript there is no class keyword and
the function serves as class definition, there is
no need of defining constructor explicitly. The
function defined for the class acts as
constructor.
• For example, in following code snippet we
have called an alert statement when class Car
is instantiated.
Property
(Class Instance) in JavaScript
• Properties are the variable that are member
of an object and can define the state of any
instance of Class. Property of a class can be
accessed within the class using this keyword.
For example, in following code snippet we
have assign a property speed to Car.
• One thing we should note here is that for
inheritance works correctly, the Properties
should be set in the prototype property of the
class (function). The above example becomes:
Methods
• To define methods in a Class, all you have to
do is just define a attribute and assign an
function to it. For example, in below code
snippet we defined a method setSpeed() for
class Car.
Inheritance in JavaScript
• JavaScript supports single class inheritance. To
create a child class that inherit parent
class, we create a Parent class object and
assign it to the Child class. In following
example we created a child class Ferrari from
parent class Car.
Object oriented programming

Contenu connexe

Tendances

power poitnt of oops
power poitnt of oopspower poitnt of oops
power poitnt of oops
Dhiraj Kumar
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 

Tendances (20)

Class as the basis of all computation
Class as the basis of all computationClass as the basis of all computation
Class as the basis of all computation
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Object Oriented Programming Principles
Object Oriented Programming PrinciplesObject Oriented Programming Principles
Object Oriented Programming Principles
 
Java Training | Online Java Training
Java Training | Online Java TrainingJava Training | Online Java Training
Java Training | Online Java Training
 
C++ unit-2-part-2
C++ unit-2-part-2C++ unit-2-part-2
C++ unit-2-part-2
 
Metaprogramming ruby
Metaprogramming rubyMetaprogramming ruby
Metaprogramming ruby
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Function-and-prototype defined classes in JavaScript
Function-and-prototype defined classes in JavaScriptFunction-and-prototype defined classes in JavaScript
Function-and-prototype defined classes in JavaScript
 
Arrays in Java
Arrays in Java Arrays in Java
Arrays in Java
 
power poitnt of oops
power poitnt of oopspower poitnt of oops
power poitnt of oops
 
Session 04 - Arrays in Java
Session 04 - Arrays in JavaSession 04 - Arrays in Java
Session 04 - Arrays in Java
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Introducing classes
Introducing classesIntroducing classes
Introducing classes
 
Java object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - BrainsmartlabsJava object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - Brainsmartlabs
 
05 ruby classes
05 ruby classes05 ruby classes
05 ruby classes
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Packages
PackagesPackages
Packages
 

En vedette (8)

Jewelry,Cagas, Bermarin (LQR1)
Jewelry,Cagas, Bermarin (LQR1)Jewelry,Cagas, Bermarin (LQR1)
Jewelry,Cagas, Bermarin (LQR1)
 
LOGOTERAPIA
LOGOTERAPIALOGOTERAPIA
LOGOTERAPIA
 
ฉันเหมือนใคร9
ฉันเหมือนใคร9ฉันเหมือนใคร9
ฉันเหมือนใคร9
 
Sloodle(68703 & 82915)
Sloodle(68703 & 82915)Sloodle(68703 & 82915)
Sloodle(68703 & 82915)
 
Presentation1
Presentation1Presentation1
Presentation1
 
Power point งานสุขศึกษา 2
Power point งานสุขศึกษา 2Power point งานสุขศึกษา 2
Power point งานสุขศึกษา 2
 
Tech4101 1 (68703& 82915)
Tech4101 1 (68703& 82915)Tech4101 1 (68703& 82915)
Tech4101 1 (68703& 82915)
 
Tech4101 1 (68703& 82915)
Tech4101 1 (68703& 82915)Tech4101 1 (68703& 82915)
Tech4101 1 (68703& 82915)
 

Similaire à Object oriented programming

Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
AnkurSingh340457
 

Similaire à Object oriented programming (20)

object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Lecture2.pdf
Lecture2.pdfLecture2.pdf
Lecture2.pdf
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
O op lecture 04
O op lecture 04O op lecture 04
O op lecture 04
 
OOP lecture 04
OOP  lecture 04OOP  lecture 04
OOP lecture 04
 
Definning class.pptx unit 3
Definning class.pptx unit 3Definning class.pptx unit 3
Definning class.pptx unit 3
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
CONSTRUCTORS.pptx
CONSTRUCTORS.pptxCONSTRUCTORS.pptx
CONSTRUCTORS.pptx
 

Dernier

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Dernier (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Object oriented programming

  • 2. • Object-oriented programming (OOP) uses “objects”– data structures consisting of datafields and methods and their interactions to design applications and computer programs • Each object can be seen as a tiny machine which is responsible for the set of task assign to it.
  • 3. • Today, many popular programming languages (such as Java, JavaScript, C#, C++, Python, PHP etc) support object-oriented programming (OOP). • JavaScript has strong object-oriented programming capabilities. Although there is differences in object-oriented capability of javascript compared to other languages.
  • 5. • Class: Defines the characteristics of the Object. Constructor: A method called at the moment of instantiation. Object: An Instance of a Class. Method: An Object capability as walk. Property: An Object characteristic, such as color. Inheritance: A Class can inherit characteristics from another Class.
  • 6. • Encapsulation: A Class defines only the characteristics of the Object, a method defines only how the method executes. Abstraction: The conjunction of complex inheritance, methods, properties of an Object must be able to simulate a reality model. Polymorphism: Different Classes might define the same method or property.
  • 7.
  • 8. The Class in JavaScript • Unlike Java, C++ etc., JavaScript does not contains class statement. JavaScript is a prototype-based language. JavaScript uses functions as classes. Defining a class is as easy as defining a function. In the example below we define a new class called Car.
  • 9. The Object (Class Instance) in JavaScript • For creating instances of any class i.e. objects use new keyword. For example, in below code snippet we created two instances of class Car.
  • 10. Constructor • Constructor is a method that is used to initiate the properties of any class instance. • Thus the constructor gets called when the class is instantiated. • As in JavaScript there is no class keyword and the function serves as class definition, there is no need of defining constructor explicitly. The function defined for the class acts as constructor.
  • 11. • For example, in following code snippet we have called an alert statement when class Car is instantiated.
  • 12. Property (Class Instance) in JavaScript • Properties are the variable that are member of an object and can define the state of any instance of Class. Property of a class can be accessed within the class using this keyword. For example, in following code snippet we have assign a property speed to Car.
  • 13.
  • 14. • One thing we should note here is that for inheritance works correctly, the Properties should be set in the prototype property of the class (function). The above example becomes:
  • 15.
  • 16. Methods • To define methods in a Class, all you have to do is just define a attribute and assign an function to it. For example, in below code snippet we defined a method setSpeed() for class Car.
  • 17.
  • 18. Inheritance in JavaScript • JavaScript supports single class inheritance. To create a child class that inherit parent class, we create a Parent class object and assign it to the Child class. In following example we created a child class Ferrari from parent class Car.