I am seeing this practice in many Laravel applications, and I don’t know the diferences o the reasons to use this.
Instead of having public static methods in the class, many people code only one static function that retrieves an instance of a class an this instace call the function.
This classes have no properties or anything that is needed to make the functions work, so I do not understand why use this way to work. I think this make code more dificult to read, in many cases.
Example, I see this laravel implementantion:
class MyClass
{
public static function instance()
{
return new MyClass();
}
public function myStuff()
{
//my stuff
}
}
//Calling it
MyClass::instance()->myStuff();
I think it would be more readable and same result making all it with static functions, like:
class MyClass
{
public static function myStuff()
{
//my stuff
}
}
//Calling it
MyClass::myStuff();
What do you think about this?