Archive

Posts Tagged ‘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.

 

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , ,

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.

 

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , ,

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.

 

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , ,

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();
?>

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: ,

Data Abstraction

Data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user.

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: ,

Data encapsulation

Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.

Data encapsulation is a mechanism of bundling the data, and the functions that use

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: ,

Implements

We use implements keyword to extend interface of class, at the same time we can implement more than one interface and one interface can be implemented by another interface.

All methods declared in an interface must be public and the variables should be constant.

This is mandatory that we must declare the body part of the method in the derived class otherwise an error message will be generated.

Example

<?php
interface a{
public function test();
}

class b implements a{
public function test(){
echo “Function Test”;
}
}

$b=new b();
$b->test();
?>

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , ,

Interface

PHP does not support multiple inheritance directly, to implement this we need Interface.

Here method are declared in the Interface body, and the body part of the method is implemented in derived class. Variables are declared as constant and it can not be changed in the child classes.

We use implement keyword to extend this kind of class, at the same time we can implement more than one interface and one interface can be implemented by another interface.

All methods declared in an interface must be public and the variables should be constant.

This is mandatory that we must declare the body part of the method in the derived class otherwise an error message will be generated.

Example

<?php
interface a{
public function test();
}

class b implements a{
public function test(){
echo “Function Test”;
}
}

$b=new b();
$b->test();
?>

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , ,

Switch to our mobile site