(no title)
chrchr
|
5 months ago
The reason to use a factory instead of 'new' is that a factory can vary the return type, unlike a plain constructor. You need a factory when, based on the constructor parameters or the system configuration, different classes of object may be instantiated. I really have to disagree with your characterization of the GoF book. The premise is that it's a set of designs that can be applied when specific situations are encountered, though, granted, if you're reading the book before you've actually seen the situation where a particular pattern can be applied, it seems abstract. Certainly, popular conceptions of patterns taken out of context make that problem worse.
1718627440|5 months ago
That's a language limitation and has nothing to do with the design pattern. You can do this just fine e.g. in Python.
idontwantthis|5 months ago
scrame|5 months ago