Last active
August 29, 2015 14:06
-
-
Save prodeveloper/cd923c2a50822a5e5d60 to your computer and use it in GitHub Desktop.
Introduce Parameter Object Refactor | After Refactor
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 | |
use DateRange; | |
/** | |
* Easy to read | |
* Easy to refactor | |
* Easy to mock and test | |
*/ | |
class Customer { | |
function amountInvoicedIn(DateRange $d_range) { | |
} | |
function amountReceicedIn(DateRange $d_range) { | |
} | |
function amountOverdueIn(DateRange $d_range) { | |
} | |
} |
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 DateRange { | |
private $end_date; | |
private $start_date; | |
function __construct($start_date, $end_date) { | |
$this->start_date = $start_date; | |
$this->end_date = $end_date; | |
} | |
function getStartDate() { | |
return $this->start_date; | |
} | |
function getEndDate() { | |
return $this->end_date; | |
} | |
} |
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 | |
/** | |
* Someone (probably your future self) mercilessly murdering your design in the name of | |
* pretty time | |
* | |
* @author jacob | |
*/ | |
class DateRangeChild extends DateRange{ | |
function getStartDate() { | |
$this->start_date; | |
return $this->makePretty($date); | |
} | |
function makePretty($date){ | |
return "Today is {$date}"; | |
} | |
} |
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 | |
/** | |
* A parameter object safe from murder | |
* | |
* @author jacob | |
*/ | |
final class DateRangeProtected { | |
protected $end_date; | |
protected $start_date; | |
function __construct($start_date, $end_date) { | |
$this->start_date = $start_date; | |
$this->end_date = $end_date; | |
} | |
function getStartDate() { | |
return $this->start_date; | |
} | |
function getEndDate() { | |
return $this->end_date; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment