Object-Oriented Programming
(OOP)
MD. ATIKUR RAHMAN
PHP
Lecture - 01
Programmer, Silkcity Solution
Trainer, CBA IT
2
Agenda
o Object-Oriented Programming (OOP)
o Procedural programming
o Procedural programming vs OOP
o Features/Principles of OOP
o Advantages of using OOP
o Class
o Object
o Class vs Object
o Object Characteristics
Object-Oriented
Programming (OOP)
OOP is a programming paradigm based on the concept of "objects", which can
contain data and code. data in the form of fields, and code, in the form of
procedures.
A common feature of objects is that procedures are attached to them and can
access and modify the object's data fields
Note : The "Don't Repeat Yourself" (DRY) principle is about reducing the
repetition of code.
4
Procedural programming is a programming paradigm
built around the idea that programs are sequences of
instructions to be executed.
Procedural
programming
PP vs 00P
Procedural programming Object-Oriented Programming
Divided into small parts called functions. Divided into small parts called objects.
follows a top-down approach. follows a bottom-up approach.
No access specifier
Has access specifiers 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.
overloading is not possible. Overloading is possible
there is no concept of data hiding and inheritance. the concept of data hiding and inheritance is used.
5
PP vs 00P
Procedural programming Object-Oriented Programming
the function is more important than the data. data is more important than function.
based on the unreal world. based on the real world.
Used for designing medium-sized programs.
Used for designing large and complex
programs.
uses the concept of procedure abstraction. uses the concept of data abstraction.
Code reusability absent Code reusability present
Examples: C, FORTRAN, Pascal, Basic, etc. Exemples: C++, Java, Python, C#,PHP etc.
6
The main
Features/Principles
of OOP
Data
Abstraction
7
Inheritance Encapsulation
Polymorphism
Advantages of
using OOP
o OOPs is very helpful in solving very complex level of problems.
o Highly complex programs can be created, handled, and maintained easily
using object-oriented programming.
o OOPs, promote code reuse, thereby reducing redundancy.
o OOPs also helps to hide the unnecessary details with the help of Data
Abstraction.
o OOPs, are based on a bottom-up approach, unlike the Structural
programming paradigm, which uses a top-down approach.
o Polymorphism offers a lot of flexibility in OOPs.
 Class
 Object
 Properties
 Methods (or Functions)
9
Understand the
following terms
Class
A class is a blueprint. It is a piece of code describing how to
manage a topic or task in the way we want.
• It is a user-defined data type
• Inside a class, we define variables, constants, member functions, and other
functionality.
• it binds data and functions together in a single unit.
• It does not consume memory at run time.
Structuring Classes
declare a class using the class
keyword
followed by the name of the class and
a set of curly braces { }
<?php
class MyClass
{
// Class properties and methods
}
?>
Object
An object is a real-world entity that has attributes, behavior, and
properties. It is referred to as an instance of the class. It contains
member functions, variables that we have defined in the class. It
occupies space in the memory.
Different objects have different states or attributes, and behaviors.
Structuring Object
We created the object $myObject from
the class MyClass with the new keyword.
The process of creating an object is also
known as instantiation.
<?php
class MyClass
{
// Class properties and methods
}
$myObject = new MyClass();
?>
class vs object
class object
It is a logical entity. It is a real-world entity.
It is conceptual. It is real.
It binds data and methods together into a single unit. It is just like a variable of a class.
It does not occupy space in the memory. It occupies space in the memory.
It is a data type that represents the blueprint of an
object.
It is an instance of the class.
It is declared once. Multiple objects can be declared.
It uses the keyword class when declared. It uses the new keyword to create an object.
A class can exist without any object. Objects cannot exist without a class.
12
13
Object
Characteristics
objects share the two common key characteristics
o State
o Behavior
State tells us how the object looks or what properties
it has.
Behavior tells us what the object does.
Object holds its state in variables that are often referred to as
properties.
Object also exposes its behavior via functions or methods.
14
Object
Characteristics
example
A bank account has the state that
consists of
Account
Number
Balance Deposit Withdraw
A bank account also has the following
behaviors
Thank you

PHP OOP Lecture - 01.pptx

  • 1.
    Object-Oriented Programming (OOP) MD. ATIKURRAHMAN PHP Lecture - 01 Programmer, Silkcity Solution Trainer, CBA IT
  • 2.
    2 Agenda o Object-Oriented Programming(OOP) o Procedural programming o Procedural programming vs OOP o Features/Principles of OOP o Advantages of using OOP o Class o Object o Class vs Object o Object Characteristics
  • 3.
    Object-Oriented Programming (OOP) OOP isa programming paradigm based on the concept of "objects", which can contain data and code. data in the form of fields, and code, in the form of procedures. A common feature of objects is that procedures are attached to them and can access and modify the object's data fields Note : The "Don't Repeat Yourself" (DRY) principle is about reducing the repetition of code.
  • 4.
    4 Procedural programming isa programming paradigm built around the idea that programs are sequences of instructions to be executed. Procedural programming
  • 5.
    PP vs 00P Proceduralprogramming Object-Oriented Programming Divided into small parts called functions. Divided into small parts called objects. follows a top-down approach. follows a bottom-up approach. No access specifier Has access specifiers 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. overloading is not possible. Overloading is possible there is no concept of data hiding and inheritance. the concept of data hiding and inheritance is used. 5
  • 6.
    PP vs 00P Proceduralprogramming Object-Oriented Programming the function is more important than the data. data is more important than function. based on the unreal world. based on the real world. Used for designing medium-sized programs. Used for designing large and complex programs. uses the concept of procedure abstraction. uses the concept of data abstraction. Code reusability absent Code reusability present Examples: C, FORTRAN, Pascal, Basic, etc. Exemples: C++, Java, Python, C#,PHP etc. 6
  • 7.
  • 8.
    Advantages of using OOP oOOPs is very helpful in solving very complex level of problems. o Highly complex programs can be created, handled, and maintained easily using object-oriented programming. o OOPs, promote code reuse, thereby reducing redundancy. o OOPs also helps to hide the unnecessary details with the help of Data Abstraction. o OOPs, are based on a bottom-up approach, unlike the Structural programming paradigm, which uses a top-down approach. o Polymorphism offers a lot of flexibility in OOPs.
  • 9.
     Class  Object Properties  Methods (or Functions) 9 Understand the following terms
  • 10.
    Class A class isa blueprint. It is a piece of code describing how to manage a topic or task in the way we want. • It is a user-defined data type • Inside a class, we define variables, constants, member functions, and other functionality. • it binds data and functions together in a single unit. • It does not consume memory at run time. Structuring Classes declare a class using the class keyword followed by the name of the class and a set of curly braces { } <?php class MyClass { // Class properties and methods } ?>
  • 11.
    Object An object isa real-world entity that has attributes, behavior, and properties. It is referred to as an instance of the class. It contains member functions, variables that we have defined in the class. It occupies space in the memory. Different objects have different states or attributes, and behaviors. Structuring Object We created the object $myObject from the class MyClass with the new keyword. The process of creating an object is also known as instantiation. <?php class MyClass { // Class properties and methods } $myObject = new MyClass(); ?>
  • 12.
    class vs object classobject It is a logical entity. It is a real-world entity. It is conceptual. It is real. It binds data and methods together into a single unit. It is just like a variable of a class. It does not occupy space in the memory. It occupies space in the memory. It is a data type that represents the blueprint of an object. It is an instance of the class. It is declared once. Multiple objects can be declared. It uses the keyword class when declared. It uses the new keyword to create an object. A class can exist without any object. Objects cannot exist without a class. 12
  • 13.
    13 Object Characteristics objects share thetwo common key characteristics o State o Behavior State tells us how the object looks or what properties it has. Behavior tells us what the object does. Object holds its state in variables that are often referred to as properties. Object also exposes its behavior via functions or methods.
  • 14.
    14 Object Characteristics example A bank accounthas the state that consists of Account Number Balance Deposit Withdraw A bank account also has the following behaviors
  • 15.