Tag Archives: Single Responsibility Principle

if-else trees vs SOLID principles

Introduction

If you have read my previous articles, or know me personally, you must know that the one kind of bad code I hate the most is if-else trees. In the first article of this weblog, I talked about if-else trees in general, exposing some general ideas about how to avoid them, remove them from the code or why they are bad, describing them as a code smell.

Today, as I have just finished writing a series of articles in French about the SOLID principles, I am going to focus on the maintainability aspect of if-else trees, and make them fight against two of the SOLID principles: the Single Responsibility Principle and the Open/Closed Principle. This will allow me to introduce some important rules to know about if-else trees. Continue reading if-else trees vs SOLID principles

SOLID Partie I : Single Responsibility Principle

Introduction

Robert C. Martin, le père de SOLID, introduit le Single Responsibility Principle (SRP) en ces termes:

“There should never be more than one reason for a class to change.”

“Il ne devrait jamais y avoir plus d’une raison de changer une classe.” Continue reading SOLID Partie I : Single Responsibility Principle