Last active
September 30, 2015 03:50
-
-
Save puiutucutu/735013997bffa312781a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MovieTheater { | |
private $objectBoxOffice; | |
private $objectMovie; | |
public function __construct(BoxOffice $boxOffice) | |
{ | |
// using composition | |
$this->objectBoxOffice = $boxOffice; | |
// using aggregation | |
$this->objectMovie = new Movie; | |
} | |
} | |
class BoxOffice { | |
private $register; | |
public function ticketDispenser() { /* */ } | |
public function cashierMachine() { /* */ } | |
} | |
Class Movie { | |
private $movie_name = 'Conan'; | |
private $rating; | |
private $duration; | |
public function playMovie() { /* */ } | |
} | |
// create a box office object | |
$boxOffice = new BoxOffice; | |
// create a movie theater object, passing the BoxOffice object as a property | |
$movieTheater = new MovieTheater($boxOffice); | |
// debugging | |
echo '<pre><code>'; | |
print_r($movieTheater); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Print Array Dump
PHP considers both objects the same, what is different however is the way that the objects were instantiated - one through composition and the other through aggregation.