Timeline for Is a python `abstract property` that returns an abstract class an example of the Factory Pattern?
Current License: CC BY-SA 4.0
4 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 19, 2020 at 16:07 | comment | added | candied_orange | @FilipMilovanović is right. Patterns are not about structure. They’re about intent. The best proof is this is that some patterns have exactly the same structure yet different names for their different intents. | |
Dec 19, 2020 at 15:56 | comment | added | Filip Milovanović | So it's enough to just say that your clients should pass one of these objects if they wish to allow some other code to invoke it as a factory, or to derive from the base class if they wish to supply their own factory. Regarding caching a previously created instance: you need to think about whether this behavior is surprising to the client or not. E.g., it might be OK if the returned object is immutable, or if client code doesn't make the assumption that it will always get a new instance. | |
Dec 19, 2020 at 15:56 | comment | added | Filip Milovanović | You are focusing on the wrong things. Patterns aren't defined by the details of a particular implementation, it's the intent and the relationships between elements that count. Factory Method doesn't require inheritance, or prevent you from caching. The idea behind it is that the code that needs to invoke the method that creates some other object doesn't know what to create, so you supply it with an object that does know - the FactoryMethod. It's literally an object that represents a creation function. In Python, you can do this with a simple lambda - it would still be the same pattern. | |
Dec 19, 2020 at 15:33 | history | answered | Blue7 | CC BY-SA 4.0 |