B
Bora Eryilmaz
Which option illustrated below is better and why?
The first option would require that the user has knowledge of the MyData
object and that he goes through two object layers.
The second option is more direct, but if one were to set all of MyData
object's properties this way, it would be a lot of methods to
write/duplicate, especially if MyData object already had its "set" functions
defined.
What is your opinion?
MyObject obj = new MyObject(); // This object has a private member that
stores an array of MyData objects
MyData *data;
// First option
data = obj.getData(1); // Get the first data object stored in obj.
data->setValue(10); // Set the value to 10
// Second option
obj.setDataValue(1, 10); // Set the value of first MyData object to 10.
The first option would require that the user has knowledge of the MyData
object and that he goes through two object layers.
The second option is more direct, but if one were to set all of MyData
object's properties this way, it would be a lot of methods to
write/duplicate, especially if MyData object already had its "set" functions
defined.
What is your opinion?
MyObject obj = new MyObject(); // This object has a private member that
stores an array of MyData objects
MyData *data;
// First option
data = obj.getData(1); // Get the first data object stored in obj.
data->setValue(10); // Set the value to 10
// Second option
obj.setDataValue(1, 10); // Set the value of first MyData object to 10.