Created
June 27, 2022 21:30
-
-
Save atakde/09caeed489f1722f02f43ed51ba39968 to your computer and use it in GitHub Desktop.
Simple Factory Design Pattern PHP Example
This file contains hidden or 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 Car | |
{ | |
public function hello() | |
{ | |
echo "Hello!"; | |
} | |
} | |
class SimpleFactory | |
{ | |
public function createCar(): Car | |
{ | |
return new Car(); | |
} | |
} | |
$factory = new SimpleFactory(); | |
$car = $factory->createCar(); | |
$car->hello(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment