Entry tags:
Java: enum is the right place for "abstract factories"
... and/or strategies.
I was pondering where do I stick my two factory strategies, or rather strategy factories - wrote an abstract class and thought about having two final static members, with well-named implementations, when it occurred to me - kaboom, it's an enum:
Sure it is obvious. But if it is, why people hardly ever do it this way?
I was pondering where do I stick my two factory strategies, or rather strategy factories - wrote an abstract class and thought about having two final static members, with well-named implementations, when it occurred to me - kaboom, it's an enum:
enum GadgetFactory {
christmasGadget {
Gadget build(User user, WeakReference<Something>) {
...
},
newYearGadget {
Gadget build(User user, WeakReference<Something>) {
...
};
abstract Gadget build(User user, WeakReference<Something>);
}
Sure it is obvious. But if it is, why people hardly ever do it this way?