Hi Bytes Community,
How to implement Association , aggregation and composition in php. Please explain with complete example.
and I called this in index.php file like this.
its output comes.
I have this code, but little confused.
Technically in case of COMPOSITION its out put should not be like given ?
because If car shall destroy then Engine shall destroy. Please solve this mystery.
Thanks
How to implement Association , aggregation and composition in php. Please explain with complete example.
Code:
<?php
// composition and aggregation demo
class Car{
function __construct() {
$engineObj = new Engine();
print "In constructor >> Car <br/>";
}
function __destruct() {
print "Destroying >> Car<br/> ";
}
}
class Engine{
function __construct() {
print "In constructor >> Engine <br/>";
}
function __destruct() {
print "Destroying >> Engine <br/>";
}
}
?>
Code:
<?php
include('classes/objects.php');
//$engineObject = new Engine();
$carObject = new Car();
?>
Code:
In constructor >> Engine In constructor >> Car Destroying >> Engine Destroying >> Car
Technically in case of COMPOSITION its out put should not be like given ?
Code:
In constructor >> Engine In constructor >> Car Destroying >> Car Destroying >> Engine
Thanks