Skip to content

Instantly share code, notes, and snippets.

@chrisortman
Last active December 30, 2015 06:49
Show Gist options
  • Save chrisortman/7792303 to your computer and use it in GitHub Desktop.
Save chrisortman/7792303 to your computer and use it in GitHub Desktop.
I've been doing this thing where I pass an 'output' object into methods. The things I like about this are * I can vary implementation of output objects like one for an MVC ViewModel and another for a WPF ViewModel * Keeps privates of business objects (for lack of a better term) private * When I have methods that need to return more than one thin…
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;
}
}
@drusellers
Copy link

And if its working for you, then rock it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment