Law of Demeter Origin Story
The Law of Demeter is important in object-oriented programming. But where does “Demeter” come from? AKA the “Principle of Least Knowledge,” here’s a simple example of the law: code that lets us ask an owner, “What is your dog’s breed?” class Dog belongs_to :owner belongs_to :breed def breed_name breed.name end end class Owner has_one :dog # ✅ Owner only knows about 'breed_name', # not what 'breed' and 'name' are. def dog_breed_name dog.breed_name end # ❌ Owner knows that dog has a 'breed', and # that 'breed' has a 'name.' def dog_breed_name dog.breed.name end end This name comes from the Demeter project, so named because the goddess Demeter is related to Zeus. So, in a way, the name and the idea aren’t related. But, I found this online: ...