Created
September 22, 2011 04:04
-
-
Save jmarnold/1234009 to your computer and use it in GitHub Desktop.
Simple Ball of Mud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
private readonly List<OrderLineItem> _lineItems = new List<OrderLineItem>(); | |
public Guid Id { get; set; } | |
public IEnumerable<OrderLineItem> LineItems { get { return _lineItems; } } | |
public bool IsInterational { get; set; } | |
public bool IsReadyToShip { get; set; } | |
public void AddLineItem(OrderLineItem item) | |
{ | |
_lineItems.Add(item); | |
} | |
} | |
public class OrderLineItem | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderProcessor | |
{ | |
public void Process(ProcessOrderMessage message) | |
{ | |
Order order; | |
var conStr = ConfigurationManager.ConnectionStrings["OrdersDb"].ConnectionString; | |
using(var con = new SqlConnection(conStr)) | |
{ | |
order = findOrder(message.Id, con); | |
} | |
if(order.IsInterational) | |
{ | |
processInternationalOrder(order); | |
} | |
else if (order.LineItems.Count() > 10) | |
{ | |
processLargeDomesticOrder(order); | |
} | |
else | |
{ | |
processDomesticOrder(order); | |
} | |
if(order.IsReadyToShip) | |
{ | |
var shipmentGateway = new ShipmentGateway(); | |
var readyToShip = new ShipOrderMessage {Id = message.Id}; | |
shipmentGateway | |
.Ship(readyToShip); | |
} | |
// why not have two? | |
using (var con = new SqlConnection(conStr)) | |
{ | |
updateDatabase(order, con); | |
} | |
} | |
private Order findOrder(Guid id, SqlConnection con) | |
{ | |
// actually do some crappy ado.net stuff | |
return new Order(); | |
} | |
private void updateDatabase(Order order, SqlConnection con) | |
{ | |
// update the shtuff | |
} | |
private void processInternationalOrder(Order order) | |
{ | |
} | |
private void processLargeDomesticOrder(Order order) | |
{ | |
} | |
private void processDomesticOrder(Order order) | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProcessOrderMessage | |
{ | |
public Guid Id { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShipOrderMessage | |
{ | |
public Guid Id { get; set; } | |
} | |
public class ShipmentGateway | |
{ | |
public void Ship(ShipOrderMessage shipOrderMessage) | |
{ | |
// does stuff that we don't care about | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment