SOLID is a set of design rules for making code easier to understand, maintain, reuse, and reason about. Although associated with object-oriented programming, these principles also apply wherever interfaces and implementations meet, including functional design. section 1.4.3 section 1.6
The acronym names five complementary principles:
- SRP — Single Responsibility Principle: give each part of the code one responsibility. section 1.4.3
- OCP — Open/Closed Principle. section 1.4.3
- LSP — Liskov Substitution Principle: implementations must preserve the behavior promised by their interfaces. section 1.4.3
- ISP — Interface Segregation Principle. section 1.4.3
- DIP — Dependency Inversion Principle. section 1.4.3
A substitution failure
An ILampSwitcher interface promises switch behavior. DaylightLamp satisfies that contract, but TableLamp throws an unexpected exception after switching. Code that accepts a list of ILampSwitcher objects and turns them all off therefore cannot substitute TableLamp transparently, violating LSP. section 1.4.3
trait ILampSwitcher { #1
def switch(onOff: bool)
}
class DaylightLamp extends ILampSwitcher #2
class TableLamp extends ILampSwitcher #3
def turnAllOff(lamps: List[ILampSwitcher]) { #4
lamps.foreach(_.switch(false))
}
The interface and turnAllOff example makes transparent substitution concrete before inspecting the faulty implementation. section 1.4.3


