SOLID principles

The word SOLID is an acronym invented by Robert C. Martin for the five basic principles of object-oriented programming. By following these five principles, a developer is more likely to create a great, durable, and maintainable application:

  • Single Responsibility Principle: A class should have only a single reason to change.
  • Open-Closed Principle: A class should be open for extension and closed for modification. This is attributed to Bertrand Meyer.
  • Liskov Substitution Principle: This was created by Barbara Liskov, and she says a class should be replaceable by others that extend that class.
  • Interface Segregation Principle: A few specific interfaces are preferable to one general-purpose interface.
  • Dependency Inversion Principle: A class should depend on abstraction instead of implementation. This means that class dependencies must be focused on what is done and forget about how it is done.

For further information on SOLID or other related principles, visit http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod.

The first four principles are part of the core of TDD thinking, since they aim to simplify the code we write. The last one is focused on classes construction and dependency relationships in the application assembly process.

All of these principles are applicable and desirable in both test and non-test driven development, because, apart from other benefits, they make our code more maintainable. The proper practical application of them is worth a whole book by itself. While we won't have time to go deep into it, we encourage you to investigate further.

In this chapter, we will see how TDD induces developers to put some of these principles into practice effortlessly. We will implement a small but fully functional version of the famous game Connect 4 with both the TDD and non-TDD approaches. Note that repetitive parts, such as Gradle project creation and so on, are omitted, as they are not considered relevant for the purpose of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.80.209