Timeline for Factory/Strategy Pattern for objects that require different pieces of data
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 28, 2020 at 21:27 | comment | added | Doc Brown |
@ungabunga: this is pretty hard to answer without knowing more about the gory details. Maybe you are looking for a more declarative approach to define your email templates? Then you could "invent" some simple, comprehensice "declaration language" and parse this instead of repeating addVariable over and over again??
|
|
Jan 28, 2020 at 21:09 | comment | added | Filip Milovanović |
@ungabunga "There is no abstraction or interface here" - sure there is; EmailTemplate build(EmailTemplate, EmailTemplateContext) <== is your abstract strategy "interface". The abstraction is not the template itself, but the algorithm that builds it (the strategy); pull those static methods into proper objects, refine the signature as you go along, and put stuff that's specific to a concrete strategy into a corresponding object/type.
|
|
Jan 28, 2020 at 19:23 | comment | added | ungabunga |
In addition, all strategies here return the same concrete object, EmailTemplate . @doc-brown There is no abstraction or interface here, its just an EmailTemplate with its backing HashMap containing different sets of key/value pairs. These EmailTemplate s being returned are simply "hydrated" which are then passed off to the template engine to be rendered (out of my control)
|
|
Jan 28, 2020 at 19:16 | comment | added | ungabunga |
I got a fairly decent implementation of this worked out, and it helps clean up the overall architecture of this, but I still don't know if it's what I am after. Almost all of the code inside of the strategies are simply addVariable("paymentAmount", "$59.99") , etc etc. So it doesn't really feel like a "strategy", just a bunch of different values being loaded into a HashMap that backs the EmailTemplate class. A lot of code (setting of key/values) is duplicated among strategies. I'm ultimately looking for a way to consolidate and make it a little bit more generic, but also be extensible later
|
|
Jan 28, 2020 at 13:50 | vote | accept | ungabunga | ||
Jan 28, 2020 at 7:31 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 307 characters in body
|
Jan 28, 2020 at 7:10 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 658 characters in body
|
Jan 28, 2020 at 6:57 | history | answered | Doc Brown | CC BY-SA 4.0 |