Yesterday I had one of those days where all of a sudden I'm shown my code isn't as good as it should be.
Oh dear.
So, something to learn, because they were right.
Two things:
Static methods
Static methods are 'horrible'. After discussing about the why, finally a good argument came up: They inhibit extension! You cannot override them, and usually it is a sign of functional programming style. That may not be bad per se, but being able to override functions is a good thing. So:
BE CAREFUL TO MARK METHODS STATIC. USUALLY, IT CAN BE DONE BETTER.
Strategies
Strategies are cool. However, I tend to push into that direction. That my not be necessarily bad, but strategies are only for compile-time decisions. Ther is a difference between implementing classes which are injected, and thereby selected at 'compile time', and actual runtime by using, say an abstract factory to determine which strategy to use for the current run.
So, note to self: only name an interface a 'strategy' when there is an abstract factory
Oh dear.
So, something to learn, because they were right.
Two things:
Static methods
Static methods are 'horrible'. After discussing about the why, finally a good argument came up: They inhibit extension! You cannot override them, and usually it is a sign of functional programming style. That may not be bad per se, but being able to override functions is a good thing. So:
BE CAREFUL TO MARK METHODS STATIC. USUALLY, IT CAN BE DONE BETTER.
Strategies
Strategies are cool. However, I tend to push into that direction. That my not be necessarily bad, but strategies are only for compile-time decisions. Ther is a difference between implementing classes which are injected, and thereby selected at 'compile time', and actual runtime by using, say an abstract factory to determine which strategy to use for the current run.
So, note to self: only name an interface a 'strategy' when there is an abstract factory
Reacties
Een reactie posten