Last active
June 20, 2019 19:14
-
-
Save jdeveloper/3dd10ff80437837793c2b33904bb9149 to your computer and use it in GitHub Desktop.
solid
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
class Circle | |
{ | |
public $radius; | |
public function __construct($radius): void | |
{ | |
$this->radius = $radius; | |
} | |
} | |
class Square | |
{ | |
public $length; | |
public function __construct($length): void | |
{ | |
$this->length = $length; | |
} | |
} | |
class SumCalculator | |
{ | |
public function sum(): float | |
{ | |
$area = []; | |
foreach($this->shapes as $shape) { | |
if($shape instanceof Square){ | |
$area[] = pow($shape->length, 2); | |
}else if($shape instanceof Circle) { | |
$area[] = pi() * pow($shape->radius, 2); | |
} | |
} | |
return array_sum($area); | |
} | |
} |
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
class Circle | |
{ | |
public $radius; | |
public function __construct($radius): void | |
{ | |
$this->radius = $radius; | |
} | |
public function area(): float | |
{ | |
return pi() * pow($this->radius, 2); | |
} | |
} | |
class Square | |
{ | |
public $length; | |
public function __construct($length): void | |
{ | |
$this->length = $length; | |
} | |
public function area(): float | |
{ | |
// logic | |
} | |
} | |
class SumCalculator | |
{ | |
public function sum(): float | |
{ | |
$area = []; | |
foreach($this->shapes as $shape) { | |
$area[] = $shape->area(); | |
} | |
return array_sum($area); | |
} | |
} |
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
class PasswordReminder { | |
private $dbConnection; | |
public function __construct(MySQLConnection $dbConnection) | |
{ | |
$this->dbConnection = $dbConnection; | |
} | |
} | |
interface DBConnectionInterface | |
{ | |
public function connect(): void; | |
} | |
class MySQLConnection implements DBConnectionInterface | |
{ | |
public function connect(): void | |
{ | |
return "Database connection"; | |
} | |
} | |
class PasswordReminder { | |
private $dbConnection; | |
public function __construct(DBConnectionInterface $dbConnection) | |
{ | |
$this->dbConnection = $dbConnection; | |
} | |
} |
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
class ExamService2 | |
{ | |
public function resolveExam(Exam $exam, array $answers): void | |
{ | |
// logic | |
} | |
} |
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
interface ExamExporterInterface interface | |
{ | |
public function export(Exam $exam): string; | |
} | |
class ExamXmlExporter implements ExamExporterInterface | |
{ | |
public function export(Exam $exam): string | |
{ | |
// logic | |
} | |
} | |
class ExamJsonExporter implements ExamExporterInterface | |
{ | |
public function export(Exam $exam): string | |
{ | |
// logic | |
} | |
} | |
class ExamCommand | |
{ | |
public function execute() | |
{ | |
// logic getting exam | |
$examService->resolveExam($exam, $answers); | |
$examExporter->export($exam); | |
} | |
} |
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
class ExamService | |
{ | |
public function resolveExam(Exam $exam, array $answers): void | |
{ | |
// logic | |
} | |
public function export(Exam $exam): string | |
{ | |
// logic | |
} | |
} | |
class ExamCommand | |
{ | |
public function execute(): void | |
{ | |
// logic getting exam | |
$examService->resolveExam($exam, $answers); | |
$examService->export($exam); | |
} | |
} |
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
class ExamService2 | |
{ | |
public function resolveExam(Exam $exam, array $answers): void | |
{ | |
// logic | |
} | |
} |
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
interface HttpClientInterface | |
{ | |
public function get($url): Response; | |
} | |
class HttpClient implements HttpClientInterface | |
{ | |
public function get($url): Response | |
{ | |
return new Response(); | |
} | |
} | |
class CachedHttpClient implement HttpClientInterface | |
{ | |
protected $httpClient; | |
protected $cached = []; | |
public function __constructor(HttpClientInterface $httpClient) | |
{ | |
$this->httpClient = $httpClient; | |
} | |
public function get($url): Resint | |
{ | |
return $this->cached[$url]; | |
} | |
} |
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
class Rectangle | |
{ | |
protected $witdth; | |
protected $height; | |
public function setWidth(int $width): void | |
{ | |
$this->width = $width; | |
} | |
public function getWidth(): int | |
{ | |
return $this->width; | |
} | |
public function setHeight(int $height): void | |
{ | |
$this->height = $height; | |
} | |
public function getHeight(): int | |
{ | |
return $this->height; | |
} | |
public function area(): int | |
{ | |
return $this->width*$this->height; | |
} | |
} | |
class Square extends Rectangle | |
{ | |
public function setWidth(int $width): void | |
{ | |
parent::setWidth($width); | |
parent::setHeight($width); | |
} | |
public function setHeight(int $height): void | |
{ | |
parent::setHeight($height); | |
parent::setWidth($height); | |
} | |
} | |
class AreaTest extends \PHPUnit_Framework_TestCase | |
{ | |
public function testArea(): void | |
{ | |
$rectangle = new Rectangle(); | |
$rectangle->setWidth(5); | |
$rectangle->setHeight(4); | |
$this->assertEquals(20, $rectangle->area()); | |
} | |
} |
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
interface Product | |
{ | |
public function getName(): string; | |
public function getStock(): int; | |
public function getNumberOfDisks(): int; | |
public function getReleaseDate(): \DateTime; | |
} | |
class CD implements Product | |
{ | |
// implmentacion | |
} | |
class DVD implements Product | |
{ | |
// implmentacion | |
} |
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
interface AgeAware | |
{ | |
public function getEdadMinima(): int; | |
} | |
class CD implements Product | |
{ | |
// implmentacion | |
} | |
class DVD implements Product, AgeAware | |
{ | |
// implmentacion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment