Timeline for Abstract Factory for methods/constructor with different arguments
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 22, 2022 at 1:42 | comment | added | Filip Milovanović | I'm saying that's OK. You can design your factories in whatever way best suits your problem. There's no abstract factory police out there. In the original Design Patterns book, they show an example where they pass one parameter that came from the factory method, and an extra parameter that came from a private field of the factory itself. You can mix and match - based on how you intend to call the methods on the abstract factory instance, decide what to define on the AbstractFactory public interface, vs what to pass through concrete factory constructors or obtain in some other way. | |
| Oct 18, 2022 at 12:14 | history | edited | ledermauss | CC BY-SA 4.0 | edited title |
| Oct 18, 2022 at 11:58 | history | edited | ledermauss | CC BY-SA 4.0 | edited title |
| Oct 18, 2022 at 11:30 | comment | added | ledermauss | So in my case all factory methods would have no parameters (since they are defined at the subclass level), and I would supply all of them to the factory at factory creation time. I cannot supply them to the factory methods, because I would have to define them at the AbstractFactory. I understand that this is normal | |
| Oct 18, 2022 at 11:17 | comment | added | Filip Milovanović | "I also wonder if this is "correct", since each Metric and Visualization subclass have different parameters in the constructor" - that is perfectly fine/normal. You can also have your factory methods take in parameters if you want to (and are able to) supply some of them at product creation time (rather than at factory creation time). The abstract factory defines an interface for creating these objects - what that interface looks like is up to you; some of your parameters can be general, others factory-specific. | |
| S Oct 18, 2022 at 8:38 | review | First questions | |||
| Oct 19, 2022 at 4:06 | |||||
| S Oct 18, 2022 at 8:38 | history | asked | ledermauss | CC BY-SA 4.0 |