↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Bringing SOLID to Elixir

The article argues that SOLID principles, though created for object-oriented programming, can be adapted to Elixir with modules and behaviours. It walks through each principle and shows how they help structure code for maintainability, extensibility, testing, and lower coupling.

Reading notes
#

  • SOLID is presented as a set of design guidelines for building software that is more maintainable, scalable, and adaptable.
  • SRP is illustrated by splitting user-related business logic into separate modules instead of keeping saving, emailing, and deletion in one place.
  • OCP is adapted in Elixir through behaviours, so new discount types can be added with new modules instead of changing the existing calculator.
  • LSP is shown with interchangeable notification modules, and a constraint on SMS messages is used to explain a case where substitution can break expected behavior.
  • ISP is explained with a vehicle behavior that is too broad, forcing car and boat modules to implement methods they do not need, then refactoring into smaller behaviours.
  • DIP is shown by making a notification service depend on a behaviour rather than concrete email or SMS modules, with configuration deciding the implementation.
  • The article closes by saying these principles support modularity, flexibility, testing, reduced complexity, and better alignment with functional programming in Elixir.