I’m trying to refactor some “sending out an email” code by dividing the steps (validate, attach related content, format, send) into separate classes that can be more easily tested, logged, and updated.
As part of this I’ve got to figure out a way for the operations to communicate validation or transient errors (“that item was deleted”) back to the originator so that it can ask the user for more info or tell them the bad news. Here is the path the thread takes (yay, a doodle)
"Controller"
. -> Outbox
. -> Validator
. -> Formatter
. -> Sender
. <-
-> Parameters, work in progress
<- Good, not so good, "you better sit down" news
So you're a thoughtful sort, between “return”, “exceptions”, or “context”… which one makes you happiest?
A. Throw an exception at any problem and let the controller divide up the ones it can handle gracefully and the ones that know my “beeper”.
B. Return some sort of Result
<T>
class to carry both the product of the operations (an email) and the enumerated results of various operations.C. Pass a context into/outof all the steps where they can indicate any parameters they can’t deal with and keep the method signatures very straightforward.
D. Son, you’re overthinking this.. Here is what you’re gonna do :
<
YourSpecialJujuHere/>
Thanks for any and all contributions, you rock in concert.