0

What's the best object layout in ASP.net or at least.. what are the advantages and disadvantages of either case:

    Public Class Dog
        Public Breed as String
        Public Type as String
        Etc....

OR the use of properties and keeping variables private

Somewhat of a debate among our team about it. Just wanted to hear thoughts.

kervin
  • 11,482
  • 5
  • 41
  • 58
jlrolin
  • 1,583
  • 9
  • 36
  • 66

1 Answers1

2

Never expose fields directly.

Use properties with private backing fields. This allows you to change implementation and to encapsulate logic around getting/setting them.

See what the Visual Basic Team have to say on this.

Also, read about the differences between fields and properties.

Community
  • 1
  • 1
Oded
  • 477,625
  • 97
  • 867
  • 998