官术网_书友最值得收藏!

Chapter 3. SOLID Design Principles

Building modular software requires strong knowledge of the class design. There are numerous guidelines out there, addressing the way we name our classes, number of variables they should have, what the size of methods should be, and so on. The PHP ecosystem managed to pack these into official PSR standard, more precisely PSR-1: Basic Coding Standard and PSR-2: Coding Style Guide. These are all general programming guidelines that keep our code readable, understandable, and maintainable.

Aside from programming guidelines, there are more specific design principles that we can apply during the class design. Ones that address the notions of low coupling, high cohesion, and strong encapsulation. We call them SOLID design principles, a term coined by Robert Cecil Martin in the early 2000s.

SOLID is an acronym for the following five principles:

  • S: Single responsibility principle (SRP)
  • O: Open/closed principle (OCP)
  • L: Liskov substitution principle (LSP)
  • I: Interface Segregation Principle (ISP)
  • D: Dependency inversion principle (DIP)

Over a decade old, the idea of SOLID principles is far from obsolete, as they are at the heart of good class design. Throughout this chapter, we will look into each of these principles, getting to understand them by observing some of the obvious violations that break them.

In this chapter, we will be covering the following topics:

  • Single responsibility principle
  • Open/closed principle
  • Liskov substitution principle
  • Interface Segregation Principle
  • Dependency inversion principle
主站蜘蛛池模板: 金乡县| 根河市| 苍溪县| 南京市| 安阳市| 亳州市| 南投市| 武平县| 宜兰市| 建瓯市| 扎囊县| 延吉市| 灌阳县| 日喀则市| 瑞昌市| 定襄县| 凌云县| 澄城县| 色达县| 黔西| 密山市| 临澧县| 米脂县| 平遥县| 泌阳县| 马山县| 博白县| 溧水县| 河西区| 广东省| 长宁县| 西充县| 漯河市| 山东| 百色市| 读书| 凉山| 嘉禾县| 兴安盟| 忻城县| 延边|