Adaptive Code via C#

Gary McLean Hall’s book ‘Adaptive Code via C#’ has been an invaluable reading experience. It has allowed me to transfer my shallow understanding of SOLID concepts that were filled with doubts and questions, to a comprehensive tool I can use on a daily basis to ensure my work is adaptable, and a pleasure to expand.


So what is SOLID anyway?

SOLID represents 5 principles that support writing code which can transform with ease to changing requirements, is extremely testable, and ensures teams can comprehend large repositories with ease.

S – Single Responsibility. SRP is pivotal in supporting ‘O’ and ‘L’. It mandates that every unit has one responsibility. I had difficulty in the past defining what this responsibility should be, but Hall’s examples and explanations tore away all the irrational perceived shortcomings that I had attached to this, and left a clear understanding of ‘how to cut the cake’. The worst part about this chapter (Chapter 5), was that it left me wanting to write code immediately, but at the same time hesitant because I hadn’t experienced the glory of the remaining ‘OLID’.

O – Open/Close principle. No matter how much I read about this, I felt I understood it, but somehow completely missed the point. It states simply that the code you write should be open to extension but closed to modification. This is further clarified in ‘L’. It’s almost like a contract; ‘always do this… never do that…’, to ensure dependency graphs aren’t broken in implementation.

L – The Liskov Substitution Principle. This was always a black duck for me, in that I never really bothered to invest the time in understanding it. It extends the foundation ‘O’ builds and explains how code may be extended, and how to compromise.

I – Interface Segregation. Interfaces are what make SOLID possible. No interfaces, no SOLID. This is a no-brainer with ‘SOL’ and ‘D’ in mind, but Hall uses this chapter constructively to further explain how these principles work together.

D – Dependency Injection. I had a warped understanding of Dependency Injection, poisoned by the many pointless implementations of Inversion of Control I had seen in my working life. Adaptive Code via C# set the record straight on this for me; it explains why dependency injection is one of THE most important aspects of modern OO development, and how it supports SOLID as a whole.

My favourite part of reading this book was its layout. It is separated in to 3 sections. The first covers the justification for SOLID, what modern software engineering encompasses, an overview of Unit Testing, and some simple design patterns. The second is strictly SOLID, and the third is a role play of an Agile team working through a project, and negotiating change as it arises. All 3 sections are a rewarding read, with lots to be gained in the subtle references alone.

An accessory to SOLID that I have consistently struggled with prior to reading was Unit Testing. I understood the point, and how to write a test, and implement it, but I had never seen any useful examples of real unit tests that provide real value. The examples expressed in Chapter 4, whilst shallow, set me on a path to bridge this gap, and I now can confidently and comfortably use unit testing to support my projects without hindrance.

Overall, the code examples are very simple to follow, and concise. If anything, they are too simple. The experienced programmer would likely look at them and understand the concept that is being displayed and discussed, however a lesser experienced programmer would probably identify all the techniques used, but may miss the underlying point of the particular arrangement in context.

The text generally read very well. I have had text books that have taken me hours to pass less than 5 pages. Adaptive code was very easy to get though more than 30 pages per hour however, and an IDE is not necessary. It was really relaxing to read. I would recommend it to all Java and C# developers interested architecture, and writing better applications, and the first section to non-programmers in the Software Engineering industry with an interest in quality software.