Principle of Least Knowledge - alexanderteplov/computer-science GitHub Wiki

The Principle of Least Knowledge

Also known as Law of Demeter

The idea behind this principle means that, inside your application, the code that you write should express knowledge only of its surroundings.

It's very close to The One Dot Principle. (When we have some function/method, its code shouldn't access data in some object throughout more than one dot, e.g. user.getAccount().getBalance().substractSum(invoiceTotal)).

So I can formulate it as: We shouldn't place any business logic not belonging to some module into this module.

It's another incarnation of the Single responsibility principle.

Links

⚠️ **GitHub.com Fallback** ⚠️