- It is a design guideline for developing software
- It is a technique to achieve loose coupling
- It's considered a good design technique, often applied in OOP
- A.K.A principle of least knowledge
- Each object should have only limited knowledge about others
- Each object should only talk to its friends, don't talk to strangers
- Only talk to your immediate friends
Don't lie to yourself!
Don't lie to yourself!
- Account only talks to Plan
- Lets suppose we have to refactor the domain model
Users might not have a profile, and the plan belongs to the profile
- And we have code like this...
- We will have to make changes in multiple places
- We only need to make a change in one class (The User class)
- O itself
- m’s parameters
- any objects created/instantiated within m
- O’s direct component objects
- A global variable, accessible by O, in the scope of m
A method m of an object O may only invoke the methods of the following kinds of objects