Design: Principle of Least Knowledge “Talk only to your immediate friends”
August 6, 2009
This principle prevent us from creating designs that have a large number of classes coupled together. When you build a lot of dependencies between many classes, you are buliding a system that will be costly to mantain and complex for others to understand.
The principle provide some guidelines: take an object and for any method in that object the principle tell us that we should only invoke methods that belong to:
- the object itself
- object passed in as a parameter to the method
- any object the method creates or instantiates
- any component of the object
Advertisement