SlideShare a Scribd company logo
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Interface
• Interface is an empty class which contains only the
declaration of methods.
• So any class which implements this interface must
contain the declared functions in it.
• Interface is nothing but a strict ruling, which helps to
extend any class and strictly implement all methods
defined in interface.
• A class can use any interface by using the implements
keyword.
• In interface you can only declare methods, but you
cannot write their body.
• That means the body of all methods must remain blank.
• One of the reasons is it implies strict rules while creating
a class.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Interface Cont…
<?
//interface.dbdriver.php
interface DBDriver
{
public function connect();
public function execute($sql);
}
?>
• Did you notice that the functions are empty in an interface? Now let's
create our MySQLDriver class, which implements this interface.
<?
//class.mysqldriver.php
include("interface.dbdriver.php");
class MySQLDriver implements DBDriver
{
}
?>
• Now if you execute the code above, it will Fatal error, since we have
not implemented all methods in child class.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Interface Cont…
<?
include("interface.dbdriver.php");
class MySQLDriver implements DBDriver
{
public function connect()
{
//connect to database
}
public function execute($query)
{
//execute the query and output result
}
}
?>
• Let's rewrite our MySQLDriver class as follows.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Abstract Classes
• An abstract class is almost the same as interface.
• Except that now the methods can contain body.
• An abstract class must also be "extended", not "implemented".
• If the extended classes have some methods with common
functionalities, then you can define those functions in an abstract
class.
<?
//abstract.reportgenerator.php
abstract class ReportGenerator
{
public function generateReport($resultArray)
{
//write code to process the multidimensional result array and
//generate HTML Report
}
}
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Abstract Classes Cont…
• Please note that we can use the abstract class and implement an
interface.
• Similar to declaring a class as abstract, you can also declare any
method as abstract.
• When a method is declared as abstract, it means that the subclass
must override that method.
<?
include("interface.dbdriver.php");
include("abstract.reportgenerator.php");
class MySQLDriver extends ReportGenerator implements DBDriver
{
public function connect()
{
//connect to database
}
public function execute($query)
{
//execute the query and output result
}
/ / you need not declare or write the generateReport method here you need not declare or write the
generateReport method here
//again as it is extended from the abstract class directly."
}
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Abstract Classes Cont…
• Please note that we can use the abstract class and implement an
interface.
• Similar to declaring a class as abstract, you can also declare any
method as abstract.
• When a method is declared as abstract, it means that the subclass
must override that method.
<?
include("interface.dbdriver.php");
include("abstract.reportgenerator.php");
class MySQLDriver extends ReportGenerator implements DBDriver
{
public function connect()
{
//connect to database
}
public function execute($query)
{
//execute the query and output result
}
/ / you need not declare or write the generateReport method here you need not declare or write the
generateReport method here
//again as it is extended from the abstract class directly."
}
?>

More Related Content

PPT
Oo abap-sap-1206973306636228-5
prakash185645
 
PPTX
iOS development introduction
paramisoft
 
PPT
Final keyword
Namrata_Thakare
 
PDF
Abap Objects for BW
Luc Vanrobays
 
PPT
Lecture13 abap on line
Milind Patil
 
PPTX
Object oriented programming in java
Elizabeth alexander
 
PDF
Abap object-oriented-programming-tutorials
cesarmendez78
 
PPTX
Features of java - javatportal
JavaTportal
 
Oo abap-sap-1206973306636228-5
prakash185645
 
iOS development introduction
paramisoft
 
Final keyword
Namrata_Thakare
 
Abap Objects for BW
Luc Vanrobays
 
Lecture13 abap on line
Milind Patil
 
Object oriented programming in java
Elizabeth alexander
 
Abap object-oriented-programming-tutorials
cesarmendez78
 
Features of java - javatportal
JavaTportal
 

What's hot (7)

ODP
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
PPTX
Final keyword in java
Hitesh Kumar
 
PPTX
Jsp tag library
sandeep54552
 
PPTX
Javascript Road Trip(es6)
Ahmed Assaf
 
PPTX
Functions in sap hana
kabilarasan R
 
PPTX
Learn To Code: Introduction to c
SadhanaParameswaran
 
PPTX
Java Chapter 04 - Writing Classes: part 2
DanWooster1
 
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Final keyword in java
Hitesh Kumar
 
Jsp tag library
sandeep54552
 
Javascript Road Trip(es6)
Ahmed Assaf
 
Functions in sap hana
kabilarasan R
 
Learn To Code: Introduction to c
SadhanaParameswaran
 
Java Chapter 04 - Writing Classes: part 2
DanWooster1
 
Ad

Viewers also liked (20)

PPTX
Ajax
Mudasir Syed
 
PPT
PHP mysql Installing my sql 5.1
Mudasir Syed
 
PPT
PHP mysql Sql
Mudasir Syed
 
PPT
Web forms and html lecture Number 2
Mudasir Syed
 
PPT
Cookies in php lecture 2
Mudasir Syed
 
PPT
Web forms and html lecture Number 5
Mudasir Syed
 
PPT
Error reporting in php
Mudasir Syed
 
PPT
Adminstrating Through PHPMyAdmin
Mudasir Syed
 
PPT
Php Mysql
Mudasir Syed
 
PPT
Time manipulation lecture 1
Mudasir Syed
 
PPT
PHP mysql Er diagram
Mudasir Syed
 
PPT
Cookies in php lecture 1
Mudasir Syed
 
PPT
PHP mysql Database normalizatin
Mudasir Syed
 
PPT
Reporting using FPDF
Mudasir Syed
 
PPT
Sql select
Mudasir Syed
 
PPT
PHP mysql Mysql joins
Mudasir Syed
 
PPT
Time manipulation lecture 2
Mudasir Syed
 
PPT
Oop in php lecture 2
Mudasir Syed
 
PPT
Form validation server side
Mudasir Syed
 
PPT
Form validation with built in functions
Mudasir Syed
 
PHP mysql Installing my sql 5.1
Mudasir Syed
 
PHP mysql Sql
Mudasir Syed
 
Web forms and html lecture Number 2
Mudasir Syed
 
Cookies in php lecture 2
Mudasir Syed
 
Web forms and html lecture Number 5
Mudasir Syed
 
Error reporting in php
Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Mudasir Syed
 
Php Mysql
Mudasir Syed
 
Time manipulation lecture 1
Mudasir Syed
 
PHP mysql Er diagram
Mudasir Syed
 
Cookies in php lecture 1
Mudasir Syed
 
PHP mysql Database normalizatin
Mudasir Syed
 
Reporting using FPDF
Mudasir Syed
 
Sql select
Mudasir Syed
 
PHP mysql Mysql joins
Mudasir Syed
 
Time manipulation lecture 2
Mudasir Syed
 
Oop in php lecture 2
Mudasir Syed
 
Form validation server side
Mudasir Syed
 
Form validation with built in functions
Mudasir Syed
 
Ad

Similar to Oop in php lecture 2 (20)

PPT
12.2 Abstract class and Interface.ppt
VISHNUSHANKARSINGH3
 
PDF
J2EE vs JavaEE
eanimou
 
PPTX
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
PPTX
JSP Directives
ShahDhruv21
 
PDF
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
nabeehmohammedtaher
 
PPTX
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
PPT
SMI - Introduction to Java
SMIJava
 
PPTX
java.pptx
PRASHANTKULKARNI133
 
PPTX
Java interfaces
Sujit Kumar
 
PDF
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
Edureka!
 
PPTX
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
PPTX
Intro to java 8
John Godoi
 
PPTX
Untitled presentation about object oriented.pptx
janetvidyaanancys
 
PDF
Understanding And Using Reflection
Ganesh Samarthyam
 
KEY
Zend framework: Getting to grips (ZF1)
Ryan Mauger
 
KEY
Webinar: Zend framework Getting to grips (ZF1)
Ryan Mauger
 
PPTX
Java interfaces
Elizabeth alexander
 
PPTX
OOFeatures_revised-2.pptx
ssuser84e52e
 
PPTX
brief introduction to core java programming.pptx
ansariparveen06
 
PDF
Drupal 8 - Core and API Changes
Shabir Ahmad
 
12.2 Abstract class and Interface.ppt
VISHNUSHANKARSINGH3
 
J2EE vs JavaEE
eanimou
 
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
JSP Directives
ShahDhruv21
 
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
nabeehmohammedtaher
 
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
SMI - Introduction to Java
SMIJava
 
Java interfaces
Sujit Kumar
 
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
Edureka!
 
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
Intro to java 8
John Godoi
 
Untitled presentation about object oriented.pptx
janetvidyaanancys
 
Understanding And Using Reflection
Ganesh Samarthyam
 
Zend framework: Getting to grips (ZF1)
Ryan Mauger
 
Webinar: Zend framework Getting to grips (ZF1)
Ryan Mauger
 
Java interfaces
Elizabeth alexander
 
OOFeatures_revised-2.pptx
ssuser84e52e
 
brief introduction to core java programming.pptx
ansariparveen06
 
Drupal 8 - Core and API Changes
Shabir Ahmad
 

More from Mudasir Syed (12)

PPT
Filing system in PHP
Mudasir Syed
 
PPTX
PHP mysql Introduction database
Mudasir Syed
 
PPT
PHP mysql Aggregate functions
Mudasir Syed
 
PPT
Form validation client side
Mudasir Syed
 
PPT
Javascript lecture 4
Mudasir Syed
 
PPT
Javascript lecture 3
Mudasir Syed
 
PPT
Javascript 2
Mudasir Syed
 
PPT
Java script lecture 1
Mudasir Syed
 
PPTX
Dom in javascript
Mudasir Syed
 
PPT
Functions in php
Mudasir Syed
 
PPT
PHP array 2
Mudasir Syed
 
PPTX
PHP array 1
Mudasir Syed
 
Filing system in PHP
Mudasir Syed
 
PHP mysql Introduction database
Mudasir Syed
 
PHP mysql Aggregate functions
Mudasir Syed
 
Form validation client side
Mudasir Syed
 
Javascript lecture 4
Mudasir Syed
 
Javascript lecture 3
Mudasir Syed
 
Javascript 2
Mudasir Syed
 
Java script lecture 1
Mudasir Syed
 
Dom in javascript
Mudasir Syed
 
Functions in php
Mudasir Syed
 
PHP array 2
Mudasir Syed
 
PHP array 1
Mudasir Syed
 

Recently uploaded (20)

PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Landforms and landscapes data surprise preview
jpinnuck
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 

Oop in php lecture 2

  • 1. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Interface • Interface is an empty class which contains only the declaration of methods. • So any class which implements this interface must contain the declared functions in it. • Interface is nothing but a strict ruling, which helps to extend any class and strictly implement all methods defined in interface. • A class can use any interface by using the implements keyword. • In interface you can only declare methods, but you cannot write their body. • That means the body of all methods must remain blank. • One of the reasons is it implies strict rules while creating a class.
  • 2. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Interface Cont… <? //interface.dbdriver.php interface DBDriver { public function connect(); public function execute($sql); } ?> • Did you notice that the functions are empty in an interface? Now let's create our MySQLDriver class, which implements this interface. <? //class.mysqldriver.php include("interface.dbdriver.php"); class MySQLDriver implements DBDriver { } ?> • Now if you execute the code above, it will Fatal error, since we have not implemented all methods in child class.
  • 3. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Interface Cont… <? include("interface.dbdriver.php"); class MySQLDriver implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } } ?> • Let's rewrite our MySQLDriver class as follows.
  • 4. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Abstract Classes • An abstract class is almost the same as interface. • Except that now the methods can contain body. • An abstract class must also be "extended", not "implemented". • If the extended classes have some methods with common functionalities, then you can define those functions in an abstract class. <? //abstract.reportgenerator.php abstract class ReportGenerator { public function generateReport($resultArray) { //write code to process the multidimensional result array and //generate HTML Report } } ?>
  • 5. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Abstract Classes Cont… • Please note that we can use the abstract class and implement an interface. • Similar to declaring a class as abstract, you can also declare any method as abstract. • When a method is declared as abstract, it means that the subclass must override that method. <? include("interface.dbdriver.php"); include("abstract.reportgenerator.php"); class MySQLDriver extends ReportGenerator implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } / / you need not declare or write the generateReport method here you need not declare or write the generateReport method here //again as it is extended from the abstract class directly." } ?>
  • 6. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Abstract Classes Cont… • Please note that we can use the abstract class and implement an interface. • Similar to declaring a class as abstract, you can also declare any method as abstract. • When a method is declared as abstract, it means that the subclass must override that method. <? include("interface.dbdriver.php"); include("abstract.reportgenerator.php"); class MySQLDriver extends ReportGenerator implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } / / you need not declare or write the generateReport method here you need not declare or write the generateReport method here //again as it is extended from the abstract class directly." } ?>