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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.