Tony Marston
Posts: 37
Nickname: tony32
Registered: May, 2007
|
|
Re: Learning About Object Oriented Programming: Big Words, Easy Concepts
|
Posted: Dec 30, 2007 7:54 AM
|
|
> Encapsulation is simply the concept that we should hide > the inner workings of our class, especially its fields, > from outside tampering.
This definition of encapsulation is totally wrong. It has nothing to do with data hiding, as explained in the following:
http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html http://www.itmweb.com/essay550.htm
The correct definition for encapsulation is "The act of placing data and the operations that perform on that data in the same class. The class then becomes the 'capsule' or container for the data and operations." The operations appear as method/function names with a number of arguments/parameters, so the only thing that is actually hidden is the code behind each method - i.e. the implementation. Making variables public, private or protected is totally irrelevant as far as encapsulation is concerned.
This is why those people who say that a class should not contain more than a certain number of variables or methods are also wrong. Either ALL the variables and methods are in a SINGLE class, in which case you DO have encapsulation, or they are split across SEVERAL classes, in which case you DO NOT have encapsulation.
It is no wonder that large numbers of programmers have difficulty in undertanding OOP when articles such as this can't even get the basics right.
|
|