<?php
// Class member access on initialization.
// You can create an object and call a method all 
// in one line.
// Introduce in PHP5.4
// Useful when using the Builder Design Pattern
// and may support DependencyInjection.
// http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/
//
class Foo
{
	public function Hi($name)
	{
		echo "Hi $name<br/>";
	}
}

class Bar
{
	public function __construct($arg)
	{	
	}
	
	public function Hi($name)
	{
		echo "Hi $name<br/>";
	}
}

(new Foo())->Hi("Bob");
(new Foo)->Hi("Fred");
(new Bar("some arg value"))->Hi("Jane");

require_once 'House.php';
use \Property\House;

// 1. Bad approach
/*
$house = new House();
$house->LockUp();
*/

// 2. Better approach
/*
require_once 'Kitchen.php';
require_once 'Door.php';
require_once 'Window.php';
use \Property\Kitchen;
use \Property\Door;
use \Property\Window;

$house = new House(
			new Kitchen(
					new Door(),
					[ 
						new Window(),
						new Window()
					]
				)
			);
			
$house->LockUp();
*/

// Dependency Injection.
// =====================
// We can test the House like this without having to test
// the Kitchen, Door and Window classes, because we can
// inject a MockKitchen object into the House and focus
// on testing just the House code.
require_once 'MockKitchen.php';
use \Property\MockKitchen;

$house = new House(new MockKitchen());
$house->LockUp();

// 3. Best approach from the application perspective is 
// to use an Builder. i.e. a separate class for building 
// the House.

require_once 'HouseBuilder.php';
use \Property\HouseBuilder;

// Use class member access on initialization to create
// the house.
$house = (new HouseBuilder())->Build();
$house->LockUp();


?>