Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php interface vs abstract class

Use an interface when you want to force developers working in your 
system (yourself included) to implement a set number of methods on the 
classes they'll be building.
Use an abstract class when you want to force developers working in your 
system (yourself included) to implement a set numbers of methods and you 
want to provide some base methods that will help them develop their child 
classes.
Another thing to keep in mind is client classes can only extend one abstract 
class, whereas they can implement multiple interfaces. So, if you're 
defining your behavior contracts in abstract classes, that means each child 
class may only conform to a single contract. Sometimes this a good thing, 
when you want to force your user-programmers along a particular path. Other 
times it would be bad. Imagine if PHP's Countable and Iterator interfaces 
were abstract classes instead of interfaces.
One approach that's common when you're uncertain which way to go (as 
mentioned by cletus below) is to create an interface, and then have your 
abstract class implement that interface.
Comment

provide difference between interface and abstract class php







Comment

PREVIOUS NEXT
Code Example
Php :: regex sl nic validation laravel 
Php :: how to create php message 1 
Php :: laravel share 
Php :: how to convert youtube video to mp3 in php 
Php :: calculate 1 day interest 
Php :: wp-admin File not found (404 error) 
Php :: laravel remove index.php from url 
Php :: php invoke method 
Php :: active class php 
Php :: php login system 
Java :: java: cannot access javax.naming.Referenceable class file for javax.naming.Referenceable not found 
Java :: printing hello world in java 
Java :: java swing make window not resizable 
Java :: how to clear terminal in java 
Java :: random item from arraylist 
Java :: java arraylist 
Java :: default code of java 
Java :: android cardview dependency 
Java :: bukkit inventory set name 
Java :: gradle springboot run 
Java :: java reentrantlock 
Java :: recyclerview snaphelper callbacks android 
Java :: Could not initialize class org.codehaus.groovy.vmplugin.VMPluginFactory 
Java :: JFrame labels 
Java :: InetAddress.getByAddress example 
Java :: bubble sort java 
Java :: internet permission android 
Java :: java how to generate guid 
Java :: java declare multilayred array values 
Java :: spring boot post request response empty body 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =