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. Other Discussions
  3. The Weird and The Wonderful
  4. Gem code

Gem code

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubyasp-net
6 Posts 4 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.
  • Z Offline
    Z Offline
    zenwalker1985
    wrote on last edited by
    #1

    Today while reviewing one of the code, i found this chunk :)

    class MyClass
    {
    private int m_SomeValue;

    public int SomeValue
    {
        get { return m\_SomeValue;}
    }
    public void SomeMethod()
    {
        var value = GetValue();
        //Some core logic on value
    }
    
    private int GetValue()
    {
        return SomeValue;
    }
    

    }

    At first i started to think is there any catch behind this style. after few mins, i found its lame to write this way and finally it was admitted ;)

    P E 2 Replies Last reply
    0
    • Z zenwalker1985

      Today while reviewing one of the code, i found this chunk :)

      class MyClass
      {
      private int m_SomeValue;

      public int SomeValue
      {
          get { return m\_SomeValue;}
      }
      public void SomeMethod()
      {
          var value = GetValue();
          //Some core logic on value
      }
      
      private int GetValue()
      {
          return SomeValue;
      }
      

      }

      At first i started to think is there any catch behind this style. after few mins, i found its lame to write this way and finally it was admitted ;)

      P Offline
      P Offline
      Paladin2000
      wrote on last edited by
      #2

      I think the code is attempting to do something like this:

      public int SomeValue {get; private set;}

      Z 1 Reply Last reply
      0
      • P Paladin2000

        I think the code is attempting to do something like this:

        public int SomeValue {get; private set;}

        Z Offline
        Z Offline
        zenwalker1985
        wrote on last edited by
        #3

        Well nope, but still there wasnt a method needed to access/retrieve a instance member value :)

        1 Reply Last reply
        0
        • Z zenwalker1985

          Today while reviewing one of the code, i found this chunk :)

          class MyClass
          {
          private int m_SomeValue;

          public int SomeValue
          {
              get { return m\_SomeValue;}
          }
          public void SomeMethod()
          {
              var value = GetValue();
              //Some core logic on value
          }
          
          private int GetValue()
          {
              return SomeValue;
          }
          

          }

          At first i started to think is there any catch behind this style. after few mins, i found its lame to write this way and finally it was admitted ;)

          E Offline
          E Offline
          ekolis
          wrote on last edited by
          #4

          It's called "double encapsulation"! Wrap your field in a property, then wrap the property in a method! It will be even more object-oriented that way!

          Z K 2 Replies Last reply
          0
          • E ekolis

            It's called "double encapsulation"! Wrap your field in a property, then wrap the property in a method! It will be even more object-oriented that way!

            Z Offline
            Z Offline
            zenwalker1985
            wrote on last edited by
            #5

            lol i bet it is!! :)

            1 Reply Last reply
            0
            • E ekolis

              It's called "double encapsulation"! Wrap your field in a property, then wrap the property in a method! It will be even more object-oriented that way!

              K Offline
              K Offline
              krumia
              wrote on last edited by
              #6

              And don't forget to declare both the field and the property as private. Otherwise other bad programmers might accidentally access them.

              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