Good morning,
I have inherited some inherited code at work, and it uses a rather unusual design pattern. The only link I could find on the forums in a similar fashion was here . The situation is that the original designer has a generic parent class (not abstract) that has a static factory method that directly references child classes.
Here is an example of this coding style found in several places in legacy code:
public static LoggerFactory getLoggerFactory(LogType type) { switch (type) { case LOG4J: return Log4JLoggerFactory.getInstance(); case LOGBACK: return LogBackLoggerFactory.getInstance(); default: throw new RuntimeException("No logger factory defined for type " + type); } }
Where Log4JLoggerFactory and LogBackLoggerFactory extend LoggerFactory.
It seems to me that this is really alien to me, but before I significantly changed the code, is there any purpose or benefit for this design template (is there even a formal name for it)?
Any thoughts or advice are appreciated. Thanks!
EDIT: after reading Yishai's answer, I thought for a link to a Wikipedia article on a strategy template . Thank you all for your answers!
Riggy source share