I came across an excellent article that helps us see the difference between Encapsulation and Information hiding; 2 OO terms that are often synonymously used. Here is the URL for the article.
Encapsulation is not information hiding
Below are excerpts from the article; things that I would like to keep in mind when I kick off a new OO implementation project.
• Encapsulation is a language construct that facilitates the bundling of data with the methods operating on that data.
• Information hiding is a design principle that strives to shield client classes from the internal workings of a class.
• Encapsulation facilitates, but does not guarantee, information hiding.
• Encapsulation rule 1: Place data and the operations that perform on that data in the same class.
• Encapsulation rule 2: Use responsibility-driven design to determine the grouping of data and operations into classes.
• Information hiding rule 1: Don't expose data items.
• Information hiding rule 2: Don't expose the difference between stored data and derived data.
• Information hiding rule 3: Don't expose a class's internal structure.
• Information hiding rule 4: Don't expose implementation details of a class.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment