CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Apr 2009
    Posts
    1,355

    Re: about properties

    Quote Originally Posted by 2kaud View Post
    The big question I have about all of this is - why??

    Your class test has the class variables public so that any user of this class can set/get the contents of these variables at will (ok with a nod towards the restrictions) but basically these are public class variables.

    The whole point of having private class variables and public getter/setter functions is to separate the underlying representation of the data with the public use of that data. So if, at a later date, it is required to change the underlying private data representation, this can be done without making changes to the public interface. Indeed, users of the class need never know that the underlying data representation has changed.

    In this case, if the test class data representation is changed, then all the code that uses that data has to be changed as well! Take a simple example. In class test you are storing the age as an integer. What about later if you want to store the age as say the number of days since 1900? As age is public, all uses of age have to be found and changed. Using class get/set functions GetAge(..) and SetAge(..) just these two functions would need to be changed to accomodate the data representation change.
    sorry to both, but it's a person thing. i love use properties instead Get\Set. sorry

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: about properties

    Quote Originally Posted by Cambalinho View Post
    sorry to both, but it's a person thing. i love use properties instead Get\Set. sorry
    So you're trying to turn C++ into another language? Why not just use the language as it's intended to be used?

    "My favorite language does this, so I'm going to get C++ to try and do the same thing" isn't the way you learn or use C++. We have threads where Java programmers had the same attitude as this, and they tried the same thing of making C++ look like Java. It was a complete mess.

    Also as 2kaud pointed out, what if getting and setting becomes more than just returning and setting a single variable? What if it becomes more complex? All of the user code has to change because now the class has changed -- that is something that should be avoided, and that is having the user change their code because something internal in the class has changed.

    What if you change the name of the variable inside that class to something else? The user now has to change their code to match the new function name, which is absolutely no good in terms of encapsulation.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; September 3rd, 2013 at 05:00 AM.

  3. #18
    Join Date
    Apr 2009
    Posts
    1,355

    Re: about properties

    Quote Originally Posted by Paul McKenzie View Post
    So you're trying to turn C++ into another language? Why not just use the language as it's intended to be used?

    "My favorite language does this, so I'm going to get C++ to try and do the same thing" isn't the way you learn or use C++. We have threads where Java programmers had the same attitude as this, and they tried the same thing of making C++ look like Java. It was a complete mess.

    Also as 2kaud pointed out, what if getting and setting becomes more than just returning and setting a single variable? What if it becomes more complex? All of the user code has to change because now the class has changed -- that is something that should be avoided, and that is having the user change their code because something internal in the class has changed.

    What if you change the name of the variable inside that class to something else? The user now has to change their code to match the new function name, which is absolutely no good in terms of encapsulation.

    Regards,

    Paul McKenzie
    not transform the C++ in another language. like you see, i'm buiding some class's using api functions. my language will have some keywords, but will use that class's
    i can build my own compiler, but i don't know do that, for now, so i just will convert my language to C++.
    that class's is for put them in header files, for be used with my language.
    i will combine the C++ power(iinclued the assembler code) with VB6 easy to use
    my language will be more like VB6, but more powerfull and with some new things

  4. #19
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: about properties

    Quote Originally Posted by Cambalinho View Post
    my language will be more like VB6, but more powerfull and with some new things
    A new VB#? Or just VB++?
    Victor Nijegorodov

  5. #20
    Join Date
    Apr 2009
    Posts
    1,355

    Re: about properties

    Quote Originally Posted by VictorN View Post
    A new VB#? Or just VB++?
    Visual Cambalinho
    (i must give it a nice name hehehe)
    yes the name Cambalinho have 1 history, that's why i use it

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured