9

Jesus fuck. Why does anyone thing you need a factory pattern when you have only one single class you create...

Comments
  • 5
    Because it allows you to mock the dependency when you are unit testing. And if your using dependency injection it allows you to switch out the implementation if needed without having to find all hard coded references. Separating the implementation from its use is always good practice.
  • 0
    @halfflat if your doing it correctly you do. A factory is to create instances of the object. Your separating the creation from its use and it allows you to dynamically switch out the resource at runtime if needed. It’s always best practice to use factories, repositories, facades or any other well established pattern as they help make the application loosely coupled and helps you maintain SOILID & DRY implementations
  • 0
    @halfflat think you need to read some design pattern books coz that’s not how it works I’m afraid. Also DI should be the thing that’s ultimately responsible for your object creation and it’s lifetime
  • 2
    Pragmatism should rule. If you think there's a chance of extension/different implementations/etc, then start with whatever pattern you deem appropriate. Otherwise, go simple.
  • 0
    Masturbating with code.

    Beware of pointy OOP based objects.
Add Comment