From 8777a86fab5723ca346defa3c01e4abe4a9c8914 Mon Sep 17 00:00:00 2001 From: tfrommen Date: Sat, 26 Mar 2016 20:27:46 +0100 Subject: [PATCH] Dependency injection. --- php/1-bad-practices/src/creating-real-objects.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/php/1-bad-practices/src/creating-real-objects.php b/php/1-bad-practices/src/creating-real-objects.php index 427f391..2c0e1ad 100644 --- a/php/1-bad-practices/src/creating-real-objects.php +++ b/php/1-bad-practices/src/creating-real-objects.php @@ -2,9 +2,15 @@ class Renderer { + private $formatter; + + public function __construct( Formatter $formatter ) { + + $this->formatter = $formatter; + } + public function render_formatted_data( $data ) { - $formatter = new Formatter(); - echo $formatter->format( $data ); + echo $this->formatter->format( $data ); } }