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,672
  • 5
  • 42
  • 59
jlrolin
  • 1,604
  • 9
  • 38
  • 67

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
  • 489,969
  • 99
  • 883
  • 1,009