13
fjmurau
5y

I hate it when (Java) programmers produce such clutter just because their OOP 101 professor told them to do so in 2005.
I refactored it using `git rm`.

Comments
  • 3
    String/enum operations here are horrible. But I do like the factory pattern
  • 0
    His heart was at the right place 😔
  • 4
    @netikras The factory pattern has a point, but only if you're creating either more than one thing or a thing complicated to create.

    But this is just pointless and ugly indirection.
  • 2
    @fjmurau Not quite. Factory pattern also enables you to do some prep work. For instance if you use a constructor with new and later on you decide you need to extend how the object is constructed (or how it's constructed depending on the environment) you will have to either bloat your constructor with unneccessary logics or replace each and every call to that constructor with a factory method call.

    If a component has a potential to become more complex or is complex already, or is likely to change a bit, or you are considering making a singleton, factory pattern does make sense.
  • 2
    @netikras You wrote "prep work", I wrote "complicated to create", we probably mean the same. Stop nitpicking, this is DevRant, not StackOverflow.

    My point: This factory was pointless! Agree?
  • 0
    @fjmurau Depends. I only see one class. Not the whole domain
  • 0
    @netikras This implementation is indirection with absolutely zero abstraction. I wonder what the domain would have to look like to justify this.

    But most of the clutter is uncommented code, and a public constant that is used nowhere in the project.
  • 0
    @fjmurau zero abstraction? Are we looking at the same snip?
  • 1
    @fjmurau I see 1 abstraction, 1 indirection, 1 maintainability point [created by the indirection] and an ability to make non-breaking backwards-compatible upgrades.
  • 0
    @netikras optional object post and pre-processing should never be done wrapped in a completely new object though; it either needs to be a subclass with more constructors (which means then you're creating a new subclass per function), or you should be using class methods to update your object.

    Unless I'm not understanding what you mean by "factory pattern".
  • 1
    Guys.. Factory pattern?
    This is 5 lines of code we are watching. For that the only pattern is KISS.
  • 2
    @Pickman exactly this

    The whole class can be replaced with
    new CreateSendNotifier("any tag srsly");

    For now, could be a case of pre-optimizing tbh
Add Comment