Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
require_once('Interface.php');

abstract class Circle implements Shape {
private $radius;

public function __construct($radius) {
$this->radius = $radius;
}

public function getRadius() {
return $this->radius;
}

public function setRadius($radius) {
$this->radius = $radius;
}

public function getArea() {
return pi() * pow($this->radius, 2);
}

public function getPerimeter() {
return 2 * pi() * $this->radius;
}
}

$circle = new Circle(5);
echo "Circle Area: <br>" . $circle->getArea(), '<br>';
echo "Circle Perimeter: <br> " . $circle->getPerimeter(), '<br>';

?>
9 changes: 9 additions & 0 deletions Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
require_once('Form.php');

interface Shape {
public function getArea();
public function getPerimeter();
};

?>
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,16 @@ Namespaces are qualifiers that solve two different problems:
2. They allow the same name to be used for more than one class

In this file you will learn how to create and use namespaces.

### [Namespaces](Vehicle.php) <!-- omit in toc -->
Main file that creates and destructs the data

### [Namespaces](Road_legal.php) <!-- omit in toc -->
Secondary file that rewrites the main data


### [Namespaces](Form.php) <!-- omit in toc -->
Main file that constructs the data using an abstract class

### [Namespaces](Interface.php) <!-- omit in toc -->
Secondary file that uses the data from the main file "Form"
41 changes: 41 additions & 0 deletions Road_legal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
require_once('Vehicle.php');


class RoadLeagal extends Vehicle {
private static $numOfCars = 0;
private $activeAero;

public function __construct($make, $model, $year, $activeAero) {
parent::__construct($make, $model, $year);
$this->activeAero = $activeAero;
self::$numOfCars++;
}

public function getActiveAero() {
return $this->activeAero;
}

public function setActiveAero($activeAero) {
$this->activeAero = $activeAero;
}

public function startAero() {
return "The active aerodinamic is working.<br>";
}

public static function getNumOfCars() {
return self::$numOfCars;
}
}

$electricCar = new RoadLeagal('Pagani', 'Huayra', 2011, 'Active');
echo $electricCar->getMake(), '<br>';
echo $electricCar->getModel(), '<br>';
echo $electricCar->getYear(), '<br>';
echo $electricCar->getActiveAero(), '<br>';
echo RoadLeagal::getNumOfCars(), '<br><br>';



?>
58 changes: 58 additions & 0 deletions Vehicle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
class Vehicle {
protected $make;
protected $model;
protected $year;

public function __construct($make, $model, $year) {
$this->make = $make;
$this->model = $model;
$this->year = $year;
}

public function __destruct() {
echo "The vehicle has been destroyed.<br>";
}

public function getMake() {
return $this->make;
}

public function getModel() {
return $this->model;
}

public function getYear() {
return $this->year;
}

public function startEngine() {
return "The engine is running.<br>";
}

public function stopEngine() {
return "The engine is off.<br>";
}

}

class Car extends Vehicle {
private $doors;

public function __construct($make, $model, $year, $doors) {
parent::__construct($make, $model, $year);
$this->doors = $doors;
}

public function getDoors() {
return $this->doors;
}
}

$car = new Car('Pagani', 'Zonda R', 1999, 2);
echo $car->getMake(), '<br>';
echo $car->getModel(), '<br>';
echo $car->getYear(), '<br>';
echo $car->getDoors(), '<br><br>';

?>