You are on page 1of 40

Object-oriented programming: As the name suggests, Object-Oriented Programming or

OOPs refers to languages that uses objects in programming. Object-oriented


programming aims to implement real-world entities like Car, Building, Laptop, Phone,
Watch.

inspiresprerana@gmail.com
Class: FRUITS
Objects

inspiresprerana@gmail.com
Class: Phones

Objects

inspiresprerana@gmail.com
Class is Blue print/template for Objects
Class is collection of similar kind of Objects
Objects are instance/copy/examples of Class

Objects Have

Features/attributes Functions/Methods

inspiresprerana@gmail.com
MOBILE PHONE

Features Functions
1)Color 1)Calling
2)Brand 2)Clicking Pictures
3)Camera Quality 3)Video
4)Battery Life 4) Scanning document
5)Memory 5)Internet
6)Model Number 6)Messaging

inspiresprerana@gmail.com
Car

Features Functions
1)Color 1)Speed
2)Brand 2)Move
3)Fuel 3)Break
4)Build Year
5)Type
6)Model
7)Number

inspiresprerana@gmail.com
Student

Features Functions
1)Roll No 1)Print Name
2)Name 2)Results
3)Last Name
4)Class
5)Section
6)Marks Obtained

inspiresprerana@gmail.com
Student class

Student1 Student2 objects

1)Roll No-101 1)Roll No-105


2)Name- Sara 2)Name-Jhon
Attributes
3)Last Name- XYZ 3)Last Name-abc
have
4)Class – 5th 4)Class-5th
different
5)Section-A 5)Section-B
values
6)Marks Obtained=300 6)Marks Obtained-400

Functions
1)Print Name()
2)Results()
Student class

Student1 Student2 objects

1)Roll No-101 1)Roll No-105


2)Name- Sara 2)Name-Jhon
Attributes
3)Last Name- XYZ 3)Last Name-abc
have
4)Class – 5th 4)Class-5th
different
5)Section-A 5)Section-B
values
6)Marks Obtained=300 6)Marks Obtained-400

Student1.printName();
Functions
Student1.results(); 1)Print Name()
2)Results()
inspiresprerana@gmail.com
Object-oriented programming: As the name suggests, Object-Oriented Programming or
OOPs refers to languages that uses objects in programming. Object-oriented
programming aims to implement real-world entities like inheritance, hiding,
polymorphism etc in programming. The main aim of OOP is to bind together the data
and the functions that operate on them so that no other part of the code can access this
data except that function.

inspiresprerana@gmail.com
Steps to create Class in P5 Editor

inspiresprerana@gmail.com
Add New File

Step -1 Create Class File

inspiresprerana@gmail.com
Class
Name Click Here
To File

*if unable to create class file


#check either you are Login?
#If Yes and unable then click File Menu>Duplicate
inspiresprerana@gmail.com
Class File

Click here to Open File Drawer

inspiresprerana@gmail.com
Click to open file
Click to open file

Class file opened..here we write


structure/blueprint of class

inspiresprerana@gmail.com
Keyword:Class
Class Name

Class names should be nouns, in mixed case with the first letter of each internal word
capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid
acronyms and abbreviations. class Watch;class Car;
inspiresprerana@gmail.com
Keywords are tokens that have special
meaning in JavaScript

if, • break,
• in, • case,
• instanceof,
• catch,
• continue,
• new,
• debugger,
• return,
• default,
• switch, • delete,
• this, • do,
• throw, • else,
• try, • finally,
• typeof, • for,
• var, • function,
• void, • class,
• const,
• while,
• enum,
• with

inspiresprerana@gmail.com
Class Structure

class MyClass {
// class methods constructor() { ...}

method1() { ... }

method2() { ... }

method3() { ... }
... }

inspiresprerana@gmail.com
y

x
Diameter
Variable/fields/features

Function/Method

inspiresprerana@gmail.com
A constructor is a function that creates an
instance of a class which is typically called
an “object”. In JavaScript,
a constructor gets called when you
declare an object using the new keyword.
The purpose of a constructor is to create
an object and set values if there are any
object properties present.
A constructor is a function that creates an instance/copy of a
class which is typically called an “object”
. In JavaScript, a constructor gets called when
you declare an object using the new keyword.
The purpose of a constructor is to create an object and
set values if there are any object properties present.
The this keyword refers to the current object in a method or constructor.

Default Value of Ball

inspiresprerana@gmail.com
Class:Car

We want Object
Object this car

Object

inspiresprerana@gmail.com
• If we have multiple copy of a car then which
car I am currently talking about we refer it as
this..
• In the same way this here refer to current
objects variable/methods.

inspiresprerana@gmail.com
Step -2 Add Class file in Index.html

inspiresprerana@gmail.com
Add in Script Tag

inspiresprerana@gmail.com
Creating a memory location and naming it as
tennisBall

inspiresprerana@gmail.com
Keyword var
Variables are the names you give to computer memory locations which are used to
store values in a computer program.
For example, assume you want to store two values 10 and 20 in your program and
at a later stage, you want to use these two values. Let's see how you will do it. Here
are the following three simple steps −

Create variables with appropriate names.

Store your values in those two variables.

Retrieve and use the stored values from the variables.


Creating variables is also called declaring variables
inspiresprerana@gmail.com
constructor() get
called

It creates a new object. The type of this object is simply object.(Ball here).Creating a copy
or instance or example of Ball and Assigned to memory locationinspiresprerana@gmail.com
tennisBall
Use of new Keyword
• It creates a new object. The type of this object is
simply object.
• It makes the this variable point to the newly
created object.
• It executes the constructor function, using the
newly created object whenever this is
mentioned.
• It returns the newly created object.
inspiresprerana@gmail.com
Calling Function

Object can access all


methods and
variable of Class
with dot(.) oprerator

inspiresprerana@gmail.com
inspiresprerana@gmail.com
Creating two objects/instances of class Ball.

Changing
default
value of
variable

inspiresprerana@gmail.com
Three Objects

inspiresprerana@gmail.com
Adding color feature to Ball Class

inspiresprerana@gmail.com
Done
inspiresprerana@gmail.com
Object-oriented programming: As the name suggests, Object-Oriented Programming or
OOPs refers to languages that uses objects in programming. Object-oriented
programming aims to implement real-world entities like inheritance, hiding,
polymorphism etc in programming. The main aim of OOP is to bind together the data
and the functions that operate on them so that no other part of the code can access
this data except that function.
A class is a blueprint that defines the variables and the methods common to all objects
of a certain kind.

In object-oriented programming, a class is an extensible program-code-template for


creating objects,
1)providing initial values for state (member variables) and
2)implementations of behavior (member functions or methods).

inspiresprerana@gmail.com

You might also like