Tag Archives: OOPS

Abstract Class vs Interface

1) For abstract class a method must be declared as abstract. Abstract methods doesn’t have any implementation.
For interface all the methods by default are abstract methods only. So one cannot declare variables or concrete methods in interfaces.

2) The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility.
All methods declared in an interface must be public.

3)Abstract class can contain variables and concrete methods.Interfaces cannot contain variables and concrete methods except constants.

4)A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.
A class can implement many interfaces and Multiple interface inheritance is possible.

 

Difference Between abstract class and interface PHP

1) For abstract class a method must be declared as abstract. Abstract methods doesn’t have any implementation.
For interface all the methods by default are abstract methods only. So one cannot declare variables or concrete methods in interfaces.

2) The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility.
All methods declared in an interface must be public.

3)Abstract class can contain variables and concrete methods.Interfaces cannot contain variables and concrete methods except constants.

4)A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.
A class can implement many interfaces and Multiple interface inheritance is possible.

 

Factory Classes

Factory classes provide an interface for creating families of related objects. Factory classes are useful when the decision of which class to use must be done at run time and cannot be hard coded during development. Factory classes encapsulate the logic needed to decide which subclass to instantiate and so removes this decision from the application, delegating it to the factory.

 

Class

A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class.

Example

<?php
class a{
function function_a(){
echo “Function A”;
}
}

a::function_a();
?>