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

Discussion in 'C++' started by Bora Eryilmaz, Apr 18, 2005.

  1. 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.
    Bora Eryilmaz, Apr 18, 2005
    #1
    1. Advertising

  2. Re: Setting properties of an object stored as a member of anotherobject

    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
    Victor Bazarov, Apr 18, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    587
    John Carson
    Jul 30, 2003
  2. momo898
    Replies:
    2
    Views:
    481
    bruce barker \(sqlwork.com\)
    Oct 12, 2006
  3. Wardie
    Replies:
    4
    Views:
    478
    Wardie
    Nov 8, 2006
  4. Praetorian
    Replies:
    11
    Views:
    2,332
    James Kanze
    Apr 3, 2008
  5. Iams

    setting control properties based on another control

    Iams, Mar 17, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    118
Loading...

Share This Page