CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2006
    Posts
    130

    Get/Set neccessary

    I have a little class. I have some variables which I would like to access from other classes. IS there any point in writing get/set for this? Why not only make the attribut public and skip the get/set method.

  2. #2
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    Re: Get/Set neccessary

    use it as a property, in your class..
    you can set each variable property to accept or only return values.

    // am assuming here that you know how to make them into a property
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Get/Set neccessary

    Because of encapsulation, the fundamental property of OOP. There is big difference between the class's protocol - how it looks out, which methods exposes to outer world, and the class implementation - which fields it contains and how it deals with them. Nothing outside you class, including other your class, have not to take care about the class implementation.

    Believe us, this is not only academic excercise. If you would use getter/setter rather then public fields, you will avoid many problems in future.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

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