The 3 Cs of Design: From Cohesion and Coupling to Connascence
Just as the forces are deeply connected, so are the concepts of coupling, cohesion, and connascence. Let's look at this example to better understand this point:
public class OrderFlow { public void Execute(int customerId, int categoryId, int[] itemIds) { var orderId = GenerateOrderId(); orderProcessor.ProcessOrder(orderId, customerId, categoryId, itemIds); invoiceProcessor.ProcessInvoice(orderId, customerId, categoryId, itemIds); ... } }
Look at this code from the point of view of coupling and cohesion. How does it look? Not really good, right? We have a long list of parameters that clearly make the method coupling score pretty high for the Execute
method...