Article Preview
Buy Now
| Print: | |
| PDF: |
Object-Oriented Thinking
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,528
Starting Page Number: 33
RBD Number: 3115
Resource File(s): None
Related Link(s): None
Known Limitations: 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.
But REALbasic is different. With the introduction of the Assigns keyword in version 5, the choice of a property versus a pair of get/set methods became a detail of implementation. You don't necessarily need to make properties private; you can begin by declaring a property as public, and later introducing get/set methods if the need arises.
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.
|










