Skip to content

Instantly share code, notes, and snippets.

@atakde
Created June 27, 2022 21:30
Show Gist options
  • Save atakde/09caeed489f1722f02f43ed51ba39968 to your computer and use it in GitHub Desktop.
Save atakde/09caeed489f1722f02f43ed51ba39968 to your computer and use it in GitHub Desktop.
Simple Factory Design Pattern PHP Example
<?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