Train Wreck

Another anti-pattern that violates LoD is what is called Train Wreck or Chain Calls. This is a chain of functions and occurs when you have a series of C# methods that are appended to each other all in a single line of code. You will know you have written a code with Train Wreck when you are spending time trying to figure out what the line of code does:

loanCalculator.    CalculateHouseLoan(loanDTO).        GetPaymentRate().            GetMaximumYearsToPay();

You might be wondering how this phenomenon violates LoD. First, the code lacks readability and it is not maintainable. Also, the line of code is not reusable as there are three method calls in only a single line of code.

This line of code can be refactored by minimizing the interactions and eliminating ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.