Chapter 7: Design Patterns and Clean Code
In the previous two chapters, we have been looking at how to write modern, object-oriented, and typed PHP 8 code. That is all well and good, but there is always going to be a difference between writing valid code and writing clean, self-documenting, and easily testable code.
In this chapter, we are going to explore some ways you can move from writing code that works through to code that works and is also a pleasure to work with throughout its life cycle, from initial writing through to long-term maintenance.
This chapter will cover the following main topics:
- Clean code overview
- Design patterns
As usual, you can find all the code samples for this chapter in the main repo for the book available on GitHub at https://github.com/PacktPublishing/The-Art-of-Modern-PHP-8
Clean code overview
When we are writing code, there are always many ways of achieving the same goals. This means that it is possible to write perfectly...