473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Setting properties of an object stored as a member of another object

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.
Jul 23 '05 #1
1 1183
Bora Eryilmaz wrote:
Which option illustrated below is better and why?
The second is better because it provides higher abstraction.
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.


V
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tamir Khason | last post by:
How can I set the type of the object added to ArrayList (type of Array List Members) Here is the code: protected ArrayList tabs = new ArrayList(); public ArrayList Tabs {
10
by: Jeff Grills | last post by:
I am an experienced C++ programmer with over 12 years of development, and I think I know C++ quite well. I'm changing jobs at the moment, and I have about a month between leaving my last job and...
3
by: redefined.horizons | last post by:
I've been reading about Python Classes, and I'm a little confused about how Python stores the state of an object. I was hoping for some help. I realize that you can't create an empty place holder...
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.