Article Preview
Buy Now
COLUMN
Keeping Data Private
Issue: 3.1 (September/October 2004)
Author: Charles Yeomans
Author Bio: Charles Yeomans is a software developer in Lexington, Kentucky.
Article Description: No description available.
Article Length (in bytes): 4,984
Starting Page Number: 33
Article Number: 3115
Related Link(s): None
Excerpt of article text...
"Data should be private" is an oft-cited dictum of object-oriented design. However, it's sometimes unclear just what people mean by this, and it becomes entangled with and confused by the capabilities of particular languages. So let's take this opportunity to get it straight.
One rather literal interpretation of this saying is that properties must never be exposed, but should be hidden behind accessor and mutator methods. In fact, this is properly a question of (class) interface design. In C++ and Java, the syntax for getting and setting the value of a data member of an object is different from function syntax. So suppose you have a C++ class whose member Foo is declared as public. Then you can write code like c.Foo = 6. But if you later want to make this member private and add get/set functions, you may be breaking a lot of code, because you cannot use this assignment syntax with a function in C++ or Java.
...End of Excerpt. Please purchase the magazine to read the full article.