↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

SOLID: The First 5 Principles of Object Oriented Design

The page introduces SOLID as the first five object-oriented design principles by Robert C. Martin and says they support software that is easier to maintain, extend, refactor, and adapt as it grows. It uses PHP examples to show how each principle changes the way classes and interfaces are organized.

Reading notes
#

  • SRP says a class should have one reason to change, so the article splits shape calculation from output formatting by moving JSON and HTML rendering into a separate outputter class.
  • OCP says classes should be open for extension and closed for modification, so shape-specific area logic moves into each shape class instead of adding more conditional branches in AreaCalculator.
  • To support OCP safely, the article introduces ShapeInterface and checks that each shape passed to the calculator implements area().
  • LSP is illustrated with VolumeCalculator, where a subtype must remain usable where the parent type is expected; returning an array from sum() breaks the outputter, so the subclass must return a compatible value.
  • ISP says clients should not be forced to depend on methods they do not use, so the article separates flat-shape and three-dimensional shape contracts instead of making every shape implement volume().
  • The article also proposes a ManageShapeInterface with calculate() as a single API for handling both flat and 3D shapes.
  • DIP says high-level modules should depend on abstractions, not concrete classes, so PasswordReminder depends on DBConnectionInterface rather than MySQLConnection.
  • The conclusion says projects following SOLID are easier to share, extend, modify, test, and refactor with fewer complications.