2 ms·
My guess would be that most factories in Java are just very thin wrapper that do "if this return new A(); if that return new B();". This just doesn't need to b
by viraptor 14y ago
My guess would be that most factories in Java are just very thin wrapper that do "if this return new A(); if that return new B();". This just doesn't need to be done explicitly in a dynamic language. Instead of creating a factory you could pass the class itself as an argument. In Python class is also a factory of its own instances, so the whole reason for wrapping it into another object disappears.
And if you do want some logic in the factory, you can just create one without changing the interface. Callee doesn't care when calling x() whether x is a type, factory, or something else. As long as it returns an instance, everyone is happy. (that makes factories disappear from the signatures)