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...