İçeriğe geç

Inner Factory Pattern in Php (Code Example)

We can use this trait if we need inner factory pattern in our class. Also we can even add some pre conditions.

trait Makeable
{
    public static function make(...$args): static
    {
        //pre conditions

        return new static(...$args);
    }
}

Usage

class User
{
    use Makeable;

    //..
}

$user = User::make();
Tarih:PhpTasarım Desenleri (Design patterns)

İlk Yorumu Siz Yapın

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir