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

    public static readonly vs accessor properties

    I have several public static readonly variables

    accessor properties are preferred over plain public fields, but is there any reason to wrap a public static readonly when it cannot possibly be written to anyway?

  2. #2
    Join Date
    Dec 2003
    Location
    UK
    Posts
    113

    Re: public static readonly vs accessor properties

    I would say "NO", because what you are trying to achieve is to have some constants. You could move them into a seperate class and declare them as constants if you like (some people do that).

    Properties are really for "attributes" of your class. Given, a constant could "belong" inside your class as well, but I cannot see benefit in wrapping them in mutator methods (properties). The benefit of properties really come in the ability to manipulate or validate the data before saving it.

    Another textbook answer would be that encaptulation is enforced by wrapping attributes as properties. Then again, I don't see myself why constants should fall in this catagory.

    But that's only my view. - Cheers

  3. #3
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: public static readonly vs accessor properties

    public static readonly is the same as const... and no. I agree with jdt. const's are needed, and its completely worthless to create accessors for constants.

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