Skip to content

Instantly share code, notes, and snippets.

@edutrul
Last active October 3, 2015 01:32
Show Gist options
  • Save edutrul/c8426162e79dee0e19d6 to your computer and use it in GitHub Desktop.
Save edutrul/c8426162e79dee0e19d6 to your computer and use it in GitHub Desktop.
exercise01 phparquitect
<?php
/**
* Exercise01.
*/
class Person {
protected $firstname;
protected $lastname;
public function __construct($firstname, $lastname) {
$this->firstname = $firstname;
$this->lastname = $lastname;
}
public final function getFullName() {
return $this->firstname . $this->lastname;
}
}
class Employee extends Person {
public static $title;
public function __construct($firstname, $lastname, $title) {
self::$title = $title;
parent::__construct($firstname, $lastname);
}
public static function printTitle() {
print self::$title;
}
}
class Intern extends Person {
public static $title = 'intern';
public static function printTitle() {
print self::$title;
}
}
class Supervisor extends Employee {
protected $employees;
public function addEmployeeManagedByMe($employee) {
$this->employees[] = $employee;
}
public function setEmployeesManagedByMe(array $employees) {
$this->employees = $employees;
}
public function getEmployeesManagedByMe() {
return $this->employees;
}
}
$person = new Person('Luis Eduardo', 'Telaya Escobedo');
print $person->getFullName();
print '<br><br>';
$employee = new Employee('abc', 'EFD', 'Employee');
Employee::printTitle();
print '<br><br>';
Intern::printTitle();
print '<br><br>';
$supervisor = new Supervisor('Eduardo', 'Telaya', 'supervisor x');
$supervisor->setEmployeesManagedByMe(array(new Employee('Edu', 'Tel', 'soft dev.'), new Employee('Alexandra', 'Bellido', 'frontend')));
$supervisor->addEmployeeManagedByMe($employee);
print_r($supervisor->getEmployeesManagedByMe());
foreach ($supervisor->getEmployeesManagedByMe() as $employee) {
print_r($employee);
print $employee->getFullName();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment