Friday, August 20, 2010

What is Encapsulation and Ripple Effects?

When we hear the word "encapsulation" we think about "the condition of being enclosed". This concept may be similar in the programming world but we got to think what is encapsulation used for?

Are we encapsulating the object to protect the object or could it be for something else?

Generally, encapsulation is often mistook for the information hiding. Of course, it can be used for information hiding but encapsulating an object is not about securing/protecting the object. "Encapsulation is about freeing your consumer from the knowledge of your implementation details. By doing so, you insulate your consumer from any ripple effect of changes to your implementation" ( from http://thetechcandy.wordpress.com/2010/01/04/encapsulation-is-not-information-hiding").

Let me elaborate this, No matter how hard we try, we will often need to go back and modify the code after an application has been deployed. This could be due to the design flaw, change in requirement or many other reason.Eventually, this can lead us to the ripple effect where we will need to change many lines of code throughout application and retest them all. Now, if we have used encapsulation correctly we can change the private data structure without affecting how an object belonging to that class gets used in client code.

1 comment:

  1. A catalogue is really an important marketing and sales material of a company and catalogue encapsulation is done to enhance the life span of those documents. Moreover this process significantly enhance the overall look of prints and graphics of catalogues by providing an elegant and a professional touch which would surely be appreciated by clients and customers.

    ReplyDelete