-
-
Save chrisortman/7792303 to your computer and use it in GitHub Desktop.
public class Payment { | |
private int _accountID; | |
private int _userID; | |
private decimal _paymentAmount; | |
/* I realize this looks almost like it should be a FI, but | |
that would just distract from the point */ | |
public void OnAccount(int id) { | |
_accountID = id; | |
} | |
public void FromUser(int userID) { | |
_userID = userID; | |
} | |
public void Amount(decimal amount) { | |
_paymentAmount = amount; | |
} | |
public void WithCard(CardData c) { | |
_cardData = c; | |
} | |
/* THIS */ | |
public void Review(ConfirmationPage page,ISomeLookupService s) { | |
page.PaymentDate = DateTime.Now; | |
page.PaymentDescription = "Credit Card ****" + _cardData.LastFour; | |
page.PaymentAccount = s.GetAccountDescription(_accountID); | |
} | |
/* INSTEAD OF */ | |
public ConfirmationPage Review(ISomeLookupService s) { | |
var page = new ConfirmationPage(); | |
page.PaymentDate = DateTime.Now; | |
page.PaymentDescription = "Credit Card ****" + _cardData.LastFour; | |
page.PaymentAccount = s.GetAccountDescription(_accountID); | |
return page; | |
} | |
} |
Possibly not. It feels dual purpose to have the setup code From/With/On mixed with the Do it code, but the only other way i could really see was to expose all the data in my 'Payment' out to whatever would do the Review
When I've done this so far, my 'Payment' is very close to a command. A lot of the time it will have a single Execute() method on it, but in some cases the command has multiple steps / phases so I was putting each step as a method like Review
void Review
void Confirm
void Submit
You're right about injectiony though, it really is just another way to invert control. I'm about to the point where I think 'new' for anything other than a value object that you only use within your method scope is going to wind up biting you.
And if its working for you, then rock it out!
its more 'injectiony' which could be nice. and since its view model-y probably should NOT be created by the Payment object.
does this function
Review
really belong here?