3 Replies
I was curious if there was a smarter way of handling the
GenerateEmail
than what I did? Its a learning example to learn method overloading, but it seems rather repeating (not DRY). Is there a way to refactor it and make it more concise?
(its all the GenerateEmail()
method overloads)First thought after looking at this is that email generation logic should not be in your model.
Either way, this looks like it'd be a good candidate for optional method parameters.
I'd also suggest not using a
bool
to flip between your generation modes as you're stuck with only two options and an enum would work better instead.
For example:
another thing for overloading: often times overloads call the highest specificity with default values. For example from your initial code
but @ded did a great job of refactoring to show how optional parameters which is a better design for your current use case