php

dan

·

Dependency Injection

·

PHP

·

Total Size: 623 B

·

·

Created: 5 years ago

·

Edited: 5 years ago

<?php class Harddrive { protected $size; public function __construct($size) { $this->size = $size; } public function getSize() { return $this->size; } } class Laptop { protected $harddrive; public function __construct(Harddrive $harddrive) { $this->harddrive = $harddrive; } public function getSize() { return $this->harddrive->getSize(); } } echo "<h2>Dependency Injection Test</h2><br>"; $laptop = new Laptop(new Harddrive(69420)); echo "<p>The sheer size of this harddrive: <strong>" . $laptop->getSize() . "</strong> GB</p>";

This is an example of Dependency Injection in PHP.

1 bit

834 views

Are you sure you want to delete?