SlideShare uma empresa Scribd logo
1 de 44
 Object oriented programming concept use to make
powerful, robust and secure programming instruction.
with any language reference there are
three very important object oriented programming
concepts.
1. Encapsulation and Data Abstraction.
2. Inheritance(Multiple and Multilevel).
3. Polymorphism.
 Real world programming.
 ability to simulate real-world event much more effectively
 Reusable of code.
 Information hiding.
 Better able to create GUI alications
 programmers are able to reach their goals faster
 Programmers are able to produce faster, more accurate
 Class is a blueprint of related data members and
methods.
 Classes are the fundamental construct behind object
oriented programming.
 It is a self contained, independent collection of
variables and functions, which work together to
perform one or more specific or related task.
 Variables within a class are called properties and
functions are called methods.
 Class always start with class name. After this we have to
write class name without parentheses. Inside curly braces
we have to define all programming logic. Eg:--

 class class_name
{
-----------
-------------
}
 Object is the instance of the class .
 Once a class has been defined, objects can be created from the
class with the new keyword.
 Class methods and properties can directly be accessed through
this object instance.
 Dot operator(->):- (->)symbol used to connect objects to their
properties or methods.
[NOTES:-We can’t access any property of the class without their object.]
 $VAR = new classname();
 new keyword is responsible to initialize a
object of the class.
 We call properties to the variables inside a class.
Properties can accept values like strings, integers, and
booleans (true/false values), like any other variable.
 Property could be public, private , protected
 class Car {
public $comp;
public $color = 'beige';
public $hasSunRoof = true;
}
 Methods are actions that can be performed
on objects. Object properties can be both
primitive values, other objects, and functions.
An object method is an object property
containing a function definition.
 Property could be public, private , protected
 <?php
 class a
 { function add($a,$b)
 { $add=$a+$b;
 echo "This is function add:--".$add;
 }
 function sub($x,$y)
 { $sub=$x-$y;
 echo "This is funcion sub--".$sub;
 }
 }
 $obj = new a;
 $obj->add(10,20);
 $obj->sub(50,20);
 ?>
 There are three levels of visibility exist,
ranging from most visible to least visible.
◦ Public
◦ Protected
◦ private
Controlling the Visibility of Properties and Methods
When working with classes, you can even restrict access to its
properties and methods using the visibility keywords for greater
control. There are three visibility keywords
•public — A public property or method can be accessed
anywhere, from within the class and outside. This is the default
visibility for all class members in PHP.
•protected — A protected property or method can only be
accessed from within the class
•ss itself or in child or inherited classes i.e. classes that extends
that class.
•private — A private property or method is accessible only from
within the class that defines it. Even child or inherited classes
cannot access private properties or methods.
<?php
class Example {
public $name="BCA II";
private $age;
}
$example = new Example;
echo $example -> name . "n";
echo $example -> age;
?>
 Constructor automatically call when object
will be initialize/found.
 PHP introduce a new functionality to define a
constructor i.e. __construct().
 By using this function we can define a
constructor and it is known as predefined
constructor.
 <?php
 class A
 {
 function testA() //function
 {
 echo "n This is test A";
 }

 function __construct() //constructor
 {
 echo "This is predefined constructor of class A";
 }
 //function A ()
 //{ echo "This is constructor a";
 // }
 }
 $obj = new A;
 $obj->testA();
 ?>
•__destruct() used to define destructor.
•It destroy the current object.
 <?php
 class A
 {
 function __construct()
 {
 echo "hello constuctor.....n ";
 }
 function __destruct() //Destructor
 {
 echo "ending up........stay at home";
 }
 }
 $obj = new A();
 unset($obj);
 ?>
 Constants are pieces of information stored in the
computer's memory which cannot be changed once
assigned.
 Class Constants are constants that are declared
within classes.
 The const keyword is used to declare a class
constant.
 The class constant should be declared inside the class
definition. No $ (dollar sign) used.
 <?php
 class Welcome
 {
 const GREET = 'Hello World';
 }
 Inside the class:
The self keyword and Scope Resolution
Operator (::) is used to access class constants
from the methods in a class.
public function greet()
{ echo self::GREET;
}

 Outside the class:
The class name and constant name is used to
access a class constant from outside a class.
echo Welcome::GREET;

<?php
class Welcome
{
const GREET = 'Hello World';
public function greet()
{ echo self::GREET;
}
}
$obj = new Welcome();
$obj -> greet();
echo "n";
echo Welcome::GREET;
echo $obj->GREET;
?>
 Static Methods and Properties can be
accessed without instantiating. (Without
creating objects)
 Static methods can be called directly without
needing an instance of the class (an object).
And, $this pseudo-variable is not available
inside static methods.
 The static keyword is used to declare static
methods.
class MyClass
{
public static function myStaticMethod()
{ echo "Hello!";
}
}
 Static methods can be accessed from outside
the class using the class name and Scope
Resolution Operator (::). (Only if the visibility
is public)
 MyClass::myStaticMethod();
<?php
class myexample
{
public static function getDomain()
{ return "Developer";
}
}
echo myexample::getDomain();
//$obj = new myexample;
//$obj->getDomain();
?>
 Static methods can be called from methods of
other classes in the same way. To do this
visibility of the static method should be
public.
<?php
class MyClass
{
public static function myStaticMethod()
{ echo "Hello";
}
}
class OtherClass
{ public function myMethod()
{MyClass::myStaticMethod();
}
}
$obj = new Otherclass;
$obj->myMethod();
?>
 $this can be used inside any method to refer
to the current object.
 $this is always a reference to the object on
which the method was invoked.
 By using inheritance concept we can inherit other class
properties with any specific class.
 In this process we have to establish relation between both
class using extends keyword.
 By using object of child class we can inherit parent class
properties.
 It has two types.
◦ Multilevel inheritance
◦ Multiple inheritance (Not available in PHP)
[multiple inheritance feature is only available in c++ prog.
language And multilevel inheritance feature is available in
programming languages like PHP, Java etc.]21
 Multiple Inheritance : we can inherit more
than one class in the same class.
 Multi-Level Inheritance: where one class can
inherit only one base class and the derived
class can become base class of some other
class.
 In Multiple inheritance like this:
 Base Class
_________________
/ | 
Class1 Class2 Class3
Multilevel Inheritance:
Base Class
||
Class1
||
Class2
 get_class():- this function returns the name of
the class from which an object was
instantiated.
 get_parent_class():- it returns the name of its
parent.
 parent():- keyword parent provides an easy
shortcut to refer to the current class parent.
<?php
class a{
public $age;
function __construct(){
echo "creating a new
".get_class($this)."--- class";
}
function setAge($age){
$this->age=$age;
}
function getAge(){
return $this->age;
}
}
class b extends a
{
public $name;
function __construct(){
parent::__construct();
}
function setName($name){
$this->name = $name;
}
function getName(){
return $this->name;
}
}
$obj = new b;
$obj->setAge(25);
$obj->setName("Kamlesh Dutt");
echo $obj->getName().'is now
'.$obj->getAge().' years old';
?>
 An abstract class is a incomplete class which has
abstract methods. The abstract methods are
those which are only declared but not defined.
 The abstract class is always inherited and this is
the responsibility of sub class to define all the
abstract method of its super class. If the sub
class does not define any single method of
abstract class, then it is also treated as abstract
class.
 It is not allowed to create an instance of a class
that has been defined as abstract.
 Abstract classes allow you to provide default
functionality for the subclasses. Common
knowledge at this point. Why is this
extremely important though? If you plan on
updating this base class throughout the life
of your program, it is best to allow that base
class to be an abstract class. Why? Because
you can make a change to it and all of the
inheriting classes will now have this new
functionality.
 If the base class will be changing often and
an interface was used instead of an abstract
class, we are going to run into problems.
Once an interface is changed, any class that
implements that will be broken.
<?php
abstract class AbstractClass
{
// Force Extending class to
define this method
abstract protected function
getValue();
abstract protected function
prefixValue($prefix);
// Common method
public function printOut()
{
print $this->getValue() .
"n";
}
}
class ConcreteClass1 extends
AbstractClass
{
protected function getValue() {
return “Parent Class”;
}
public function
prefixValue($prefix) {
return "{$prefix}calling parent";
}
}
$class1 = new ConcreteClass1;
$class1->printOut();
echo $class1->prefixValue(‘Child') .
“n";
?>
//Parent Class
Child calling parent
 Object interfaces allow you to create code
which specifies which methods a class must
implement, without having to define how
these methods are handled.
 Interfaces are defined using the interface
keyword, in the same way as a standard class,
but without any of the methods having their
contents defined.
 All methods declared in an interface must be
public, this is the nature of an interface.
 implements
To implement an interface, the implements
operator is used. All methods in the interface
must be implemented within a class; failure to do
so will result in a fatal error. Classes may
implement more than one interface if desired by
separating each interface with a comma.
 Note:
A class cannot implement two interfaces that
share function names, since it would cause
ambiguity.
 Interfaces provides a form of multiple
inheritance . An abstract class can extend one
other class.
 A class may implements severeal interface.
But incase of abstract class, class may extend
only one single abstract class.
 Interfaces are slow as it requires extra
indirection to find corresponding method in
the actual class where abstract class are fast.
 Php 5 introduces the final keyword, which
prevents child classes from overriding a
method by prefixing the definition with final.
If the class itself is being defined final then it
can not be extended.
 Properties can’t be declared final, only classes
and methods may be declared as final.
 It is used to test if an object is an instance of
a particular class. This operator returns true if
the object instance has the named class
anywhere in its parent tree.
 <?php
 class a
 {
 }
 class Mammal extends a
 {

 }
 class Human extends Mammal
 {

 }
 $obj = new Human;
 echo ($obj instanceof a ?'true':'false';
 ?>

Mais conteúdo relacionado

Mais procurados

Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in phpAashiq Kuchey
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPWildan Maulana
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHPLorna Mitchell
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5Jason Austin
 
Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Alena Holligan
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with pythonArslan Arshad
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 

Mais procurados (20)

Python advance
Python advancePython advance
Python advance
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
PHP- Introduction to Object Oriented PHP
PHP-  Introduction to Object Oriented PHPPHP-  Introduction to Object Oriented PHP
PHP- Introduction to Object Oriented PHP
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
 
Oops in PHP
Oops in PHPOops in PHP
Oops in PHP
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
 
Php Oop
Php OopPhp Oop
Php Oop
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Introduction to OOP(in java) BY Govind Singh
Introduction to OOP(in java)  BY Govind SinghIntroduction to OOP(in java)  BY Govind Singh
Introduction to OOP(in java) BY Govind Singh
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 
Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 

Semelhante a Only oop

Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptxrani marri
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Alena Holligan
 
PHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptxPHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptxAtikur Rahman
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2Usman Mehmood
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Alena Holligan
 
Application package
Application packageApplication package
Application packageJAYAARC
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
Object_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdfObject_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdfGammingWorld2
 
Take the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpTake the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpAlena Holligan
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHPwahidullah mudaser
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascriptUsman Mehmood
 

Semelhante a Only oop (20)

UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18
 
PHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptxPHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptx
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Application package
Application packageApplication package
Application package
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Object_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdfObject_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdf
 
Take the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpTake the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphp
 
Inheritance
InheritanceInheritance
Inheritance
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 

Último

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 

Último (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 

Only oop

  • 1.
  • 2.  Object oriented programming concept use to make powerful, robust and secure programming instruction. with any language reference there are three very important object oriented programming concepts. 1. Encapsulation and Data Abstraction. 2. Inheritance(Multiple and Multilevel). 3. Polymorphism.
  • 3.  Real world programming.  ability to simulate real-world event much more effectively  Reusable of code.  Information hiding.  Better able to create GUI alications  programmers are able to reach their goals faster  Programmers are able to produce faster, more accurate
  • 4.  Class is a blueprint of related data members and methods.  Classes are the fundamental construct behind object oriented programming.  It is a self contained, independent collection of variables and functions, which work together to perform one or more specific or related task.  Variables within a class are called properties and functions are called methods.
  • 5.  Class always start with class name. After this we have to write class name without parentheses. Inside curly braces we have to define all programming logic. Eg:--   class class_name { ----------- ------------- }
  • 6.  Object is the instance of the class .  Once a class has been defined, objects can be created from the class with the new keyword.  Class methods and properties can directly be accessed through this object instance.  Dot operator(->):- (->)symbol used to connect objects to their properties or methods. [NOTES:-We can’t access any property of the class without their object.]
  • 7.  $VAR = new classname();  new keyword is responsible to initialize a object of the class.
  • 8.  We call properties to the variables inside a class. Properties can accept values like strings, integers, and booleans (true/false values), like any other variable.  Property could be public, private , protected  class Car { public $comp; public $color = 'beige'; public $hasSunRoof = true; }
  • 9.  Methods are actions that can be performed on objects. Object properties can be both primitive values, other objects, and functions. An object method is an object property containing a function definition.  Property could be public, private , protected
  • 10.  <?php  class a  { function add($a,$b)  { $add=$a+$b;  echo "This is function add:--".$add;  }  function sub($x,$y)  { $sub=$x-$y;  echo "This is funcion sub--".$sub;  }  }  $obj = new a;  $obj->add(10,20);  $obj->sub(50,20);  ?>
  • 11.  There are three levels of visibility exist, ranging from most visible to least visible. ◦ Public ◦ Protected ◦ private
  • 12. Controlling the Visibility of Properties and Methods When working with classes, you can even restrict access to its properties and methods using the visibility keywords for greater control. There are three visibility keywords •public — A public property or method can be accessed anywhere, from within the class and outside. This is the default visibility for all class members in PHP. •protected — A protected property or method can only be accessed from within the class •ss itself or in child or inherited classes i.e. classes that extends that class. •private — A private property or method is accessible only from within the class that defines it. Even child or inherited classes cannot access private properties or methods.
  • 13. <?php class Example { public $name="BCA II"; private $age; } $example = new Example; echo $example -> name . "n"; echo $example -> age; ?>
  • 14.  Constructor automatically call when object will be initialize/found.  PHP introduce a new functionality to define a constructor i.e. __construct().  By using this function we can define a constructor and it is known as predefined constructor.
  • 15.  <?php  class A  {  function testA() //function  {  echo "n This is test A";  }   function __construct() //constructor  {  echo "This is predefined constructor of class A";  }  //function A ()  //{ echo "This is constructor a";  // }  }  $obj = new A;  $obj->testA();  ?>
  • 16. •__destruct() used to define destructor. •It destroy the current object.
  • 17.  <?php  class A  {  function __construct()  {  echo "hello constuctor.....n ";  }  function __destruct() //Destructor  {  echo "ending up........stay at home";  }  }  $obj = new A();  unset($obj);  ?>
  • 18.  Constants are pieces of information stored in the computer's memory which cannot be changed once assigned.  Class Constants are constants that are declared within classes.  The const keyword is used to declare a class constant.  The class constant should be declared inside the class definition. No $ (dollar sign) used.  <?php  class Welcome  {  const GREET = 'Hello World';  }
  • 19.  Inside the class: The self keyword and Scope Resolution Operator (::) is used to access class constants from the methods in a class. public function greet() { echo self::GREET; } 
  • 20.  Outside the class: The class name and constant name is used to access a class constant from outside a class. echo Welcome::GREET; 
  • 21. <?php class Welcome { const GREET = 'Hello World'; public function greet() { echo self::GREET; } } $obj = new Welcome(); $obj -> greet(); echo "n"; echo Welcome::GREET; echo $obj->GREET; ?>
  • 22.  Static Methods and Properties can be accessed without instantiating. (Without creating objects)  Static methods can be called directly without needing an instance of the class (an object). And, $this pseudo-variable is not available inside static methods.  The static keyword is used to declare static methods.
  • 23. class MyClass { public static function myStaticMethod() { echo "Hello!"; } }
  • 24.  Static methods can be accessed from outside the class using the class name and Scope Resolution Operator (::). (Only if the visibility is public)  MyClass::myStaticMethod();
  • 25. <?php class myexample { public static function getDomain() { return "Developer"; } } echo myexample::getDomain(); //$obj = new myexample; //$obj->getDomain(); ?>
  • 26.  Static methods can be called from methods of other classes in the same way. To do this visibility of the static method should be public.
  • 27. <?php class MyClass { public static function myStaticMethod() { echo "Hello"; } } class OtherClass { public function myMethod() {MyClass::myStaticMethod(); } } $obj = new Otherclass; $obj->myMethod(); ?>
  • 28.  $this can be used inside any method to refer to the current object.  $this is always a reference to the object on which the method was invoked.
  • 29.  By using inheritance concept we can inherit other class properties with any specific class.  In this process we have to establish relation between both class using extends keyword.  By using object of child class we can inherit parent class properties.  It has two types. ◦ Multilevel inheritance ◦ Multiple inheritance (Not available in PHP) [multiple inheritance feature is only available in c++ prog. language And multilevel inheritance feature is available in programming languages like PHP, Java etc.]21
  • 30.  Multiple Inheritance : we can inherit more than one class in the same class.  Multi-Level Inheritance: where one class can inherit only one base class and the derived class can become base class of some other class.
  • 31.  In Multiple inheritance like this:  Base Class _________________ / | Class1 Class2 Class3 Multilevel Inheritance: Base Class || Class1 || Class2
  • 32.  get_class():- this function returns the name of the class from which an object was instantiated.  get_parent_class():- it returns the name of its parent.  parent():- keyword parent provides an easy shortcut to refer to the current class parent.
  • 33. <?php class a{ public $age; function __construct(){ echo "creating a new ".get_class($this)."--- class"; } function setAge($age){ $this->age=$age; } function getAge(){ return $this->age; } } class b extends a { public $name; function __construct(){ parent::__construct(); } function setName($name){ $this->name = $name; } function getName(){ return $this->name; } } $obj = new b; $obj->setAge(25); $obj->setName("Kamlesh Dutt"); echo $obj->getName().'is now '.$obj->getAge().' years old'; ?>
  • 34.  An abstract class is a incomplete class which has abstract methods. The abstract methods are those which are only declared but not defined.  The abstract class is always inherited and this is the responsibility of sub class to define all the abstract method of its super class. If the sub class does not define any single method of abstract class, then it is also treated as abstract class.  It is not allowed to create an instance of a class that has been defined as abstract.
  • 35.  Abstract classes allow you to provide default functionality for the subclasses. Common knowledge at this point. Why is this extremely important though? If you plan on updating this base class throughout the life of your program, it is best to allow that base class to be an abstract class. Why? Because you can make a change to it and all of the inheriting classes will now have this new functionality.
  • 36.  If the base class will be changing often and an interface was used instead of an abstract class, we are going to run into problems. Once an interface is changed, any class that implements that will be broken.
  • 37. <?php abstract class AbstractClass { // Force Extending class to define this method abstract protected function getValue(); abstract protected function prefixValue($prefix); // Common method public function printOut() { print $this->getValue() . "n"; } } class ConcreteClass1 extends AbstractClass { protected function getValue() { return “Parent Class”; } public function prefixValue($prefix) { return "{$prefix}calling parent"; } } $class1 = new ConcreteClass1; $class1->printOut(); echo $class1->prefixValue(‘Child') . “n"; ?> //Parent Class Child calling parent
  • 38.  Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.  Interfaces are defined using the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined.  All methods declared in an interface must be public, this is the nature of an interface.
  • 39.  implements To implement an interface, the implements operator is used. All methods in the interface must be implemented within a class; failure to do so will result in a fatal error. Classes may implement more than one interface if desired by separating each interface with a comma.  Note: A class cannot implement two interfaces that share function names, since it would cause ambiguity.
  • 40.  Interfaces provides a form of multiple inheritance . An abstract class can extend one other class.  A class may implements severeal interface. But incase of abstract class, class may extend only one single abstract class.  Interfaces are slow as it requires extra indirection to find corresponding method in the actual class where abstract class are fast.
  • 41.  Php 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it can not be extended.  Properties can’t be declared final, only classes and methods may be declared as final.
  • 42.
  • 43.  It is used to test if an object is an instance of a particular class. This operator returns true if the object instance has the named class anywhere in its parent tree.
  • 44.  <?php  class a  {  }  class Mammal extends a  {   }  class Human extends Mammal  {   }  $obj = new Human;  echo ($obj instanceof a ?'true':'false';  ?>