The fact is that since the implementation of the class is hidden from you you don''t actually know how the position is stored internally, i have seen some classes where the position is stored as a 4x4(no sure if it was 3x3) for some computations they make, the new Point3D () approach would create temporary unneeded objects, now if some people use setXXX and others use XXX, after years of development the language will grow lexical inconsistences. Also using setXXX is more consistent with the idea that classes are logical units that manage themselves and any state belongs to the class
Anyway I''m not against properties, i was just stating the actual opinions about them.
C# and C++ and DirectX
AFAIK, properties are supported both in Visual C++ and Borland CBuilder as:
class Object
{
public:
int GetSize() const { return this->size; }
void SetSize(int value) { this->size = value; }
__declspec( property( get=GetSize,put=SetSize ) ) int Size;
private:
int size;
};
int main()
{
Object obj;
obj.Size = 5;
obj.SetSize(5);
int size1 = obj.Size;
int size2 = obj.GetSize();
assert(size1 == 5 && size2 == 5);
}
[edited by - mishikel on March 11, 2004 12:47:00 PM]
class Object
{
public:
int GetSize() const { return this->size; }
void SetSize(int value) { this->size = value; }
__declspec( property( get=GetSize,put=SetSize ) ) int Size;
private:
int size;
};
int main()
{
Object obj;
obj.Size = 5;
obj.SetSize(5);
int size1 = obj.Size;
int size2 = obj.GetSize();
assert(size1 == 5 && size2 == 5);
}
[edited by - mishikel on March 11, 2004 12:47:00 PM]
"The problem of properties is that since you don''t actually know what the code is doing(if setting a member or performing an action) would you trust time critical code to use them? "
The same ''problem'' exists with plain function calls.
The same ''problem'' exists with plain function calls.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement