I like the expressiveness of User::register(...), User::deSerialize(), User::import(), User::fromThatScammyMailWeSentAround() (all static factories) over having it in a factory that has the same effect. The actual method is usually functionally pure anyway.
so anything that is either an entity or a value in my stuff does not have a public __construct anymore
@ThW I think the cohesion is actually a win here, plus remember that it's not actually "on the class", since a static method is just a function slammed into a namespace after all
(as long as you don't use static state, but then you'd be laravelishly foolish)
so.. I'm working on some code I haven't given love to in some time, and I see this $list = new VideoCollection(new LengthSpecification(6));
I'm not quite sure where I was inspired, but I realize the implementation I did never really was able to manage multiple specifications. Does anyone use that, and could point me towards some kind of principle to do that?
I have a need for objects which abstract an array. I find myself rewriting methods like "getByKey", "deleteByKey" etc, and it is opening up holes in my type hinting by saying "Array" instead of a class name.
It's my understanding this is exactly what collections are for.
But, I don't know how to write one so that I can iterate over it with loops,
Another problem I had when I attempted to write one is that I STILL ended up rewriting methods like "getByKey", "deleteByKey", etc. over and over again for each collection class.