1Define the following terms with simple PHP snippet codes Yo

1.Define the following terms with simple PHP snippet codes. You don’t have to write the entire code and compile, but the code should use correct syntax. (For example, don’t leave a ; out at the end of the line or not have a $ sign before the variable).
-Inheritance
-Polymorphism
-Encapsulation

2.Use an interface or abstract class program and customize it using your creativity to show the usage of Interface or Abstraction in PHP language. Make sure you have a good program purpose which gives a good description of the program.

Solution

1.) Inheritance -Inheritance is a well-established programming principle, and PHPmakes use of this principle in its object model. This principle will affect the way many classes and objects relate to one another.

class HTML
{
protected $name;
public $id;
private $with;
protected function basicAttribute
{
return \"name=\'$this->name\' id=\'$this->id\'\";
}
}
Class HTML_div extends HTML
{
public function __construct($id , $name)
{
$this->id = $id;
$this->name = $name;
}

Polymorphism -polymorphism is the ability to appear in different forms. Technically, it is the ability to redefine methods for derived classes. Poly means many and morphism means forms.

Encapsulation - Encapsulation is just wrapping some data in an object. The term \"encapsulation\" is often used interchangeably with \"information hiding\".

2.)

<?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() . \"\ \";
    }
}

class ConcreteClass1 extends AbstractClass
{
    protected function getValue() {
        return \"ConcreteClass1\";
    }

    public function prefixValue($prefix) {
        return \"{$prefix}ConcreteClass1\";
    }
}

class ConcreteClass2 extends AbstractClass
{
    public function getValue() {
        return \"ConcreteClass2\";
    }

    public function prefixValue($prefix) {
        return \"{$prefix}ConcreteClass2\";
    }
}

$class1 = new ConcreteClass1;
$class1->printOut();
echo $class1->prefixValue(\'FOO_\') .\"\ \";

$class2 = new ConcreteClass2;
$class2->printOut();
echo $class2->prefixValue(\'FOO_\') .\"\ \";
?>

1.Define the following terms with simple PHP snippet codes. You don’t have to write the entire code and compile, but the code should use correct syntax. (For ex
1.Define the following terms with simple PHP snippet codes. You don’t have to write the entire code and compile, but the code should use correct syntax. (For ex

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site