Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Class data members

Class data members

Scheduled Pinned Locked Moved Design and Architecture
question
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CodingYoshi
    wrote on last edited by
    #1

    When should a class access its own data members through a property rather than directly access them?

    P L B P 4 Replies Last reply
    0
    • C CodingYoshi

      When should a class access its own data members through a property rather than directly access them?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Only when you really need to. Accessing through the property involves more work in the IL than actually directly accessing them.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      L 1 Reply Last reply
      0
      • P Pete OHanlon

        Only when you really need to. Accessing through the property involves more work in the IL than actually directly accessing them.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Pete O'Hanlon wrote:

        Only when you really need to.

        :laugh::laugh: Ok, then when do you really need to? ;P

        led mike

        1 Reply Last reply
        0
        • C CodingYoshi

          When should a class access its own data members through a property rather than directly access them?

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          CodingYoshi wrote:

          When should a class access its own data members through a property rather than directly access them?

          Never. There is no such thing as "property" in C++.

          led mike

          1 Reply Last reply
          0
          • C CodingYoshi

            When should a class access its own data members through a property rather than directly access them?

            B Offline
            B Offline
            Brady Kelly
            wrote on last edited by
            #5

            When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic (:~) wherever you directly change the property value.

            Unscrambling Eggs: Decompiling ASP.NET

            S R 2 Replies Last reply
            0
            • B Brady Kelly

              When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic (:~) wherever you directly change the property value.

              Unscrambling Eggs: Decompiling ASP.NET

              S Offline
              S Offline
              stavinski
              wrote on last edited by
              #6

              Another example is wrapping up access to a class member in a lock statement, so that your guaranteed that the value is correct if it updated by another thread http://www.yoda.arachsys.com/csharp/threads/volatility.shtml[^]

              1 Reply Last reply
              0
              • B Brady Kelly

                When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic (:~) wherever you directly change the property value.

                Unscrambling Eggs: Decompiling ASP.NET

                R Offline
                R Offline
                Robert C Cartaino
                wrote on last edited by
                #7

                Brady Kelly wrote:

                When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic ( [Unsure] ) wherever you directly change the property value.

                That's why I would always access a data member through the property, if one is provided by the class designer. Even if it appears that accessing the member directly would accomplish the same thing, you don't know what what might be added to the property later. That's what properties are for; to provide controlled access to a data member. Why circumvent it? Robert C. Cartaino

                1 Reply Last reply
                0
                • C CodingYoshi

                  When should a class access its own data members through a property rather than directly access them?

                  P Offline
                  P Offline
                  Paul Conrad
                  wrote on last edited by
                  #8

                  Just when they need to.

                  "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups