Re: Classes, Properties, and structures
From: Herfried K. Wagner [MVP] (hirf-spam-me-here_at_gmx.at)
Date: 10/24/04
- Next message: OpticTygre: "Re: Classes, Properties, and structures"
- Previous message: Herfried K. Wagner [MVP]: "Re: declaration expected was unexpected"
- In reply to: OpticTygre: "Classes, Properties, and structures"
- Next in thread: OpticTygre: "Re: Classes, Properties, and structures"
- Reply: OpticTygre: "Re: Classes, Properties, and structures"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 24 Oct 2004 23:10:05 +0200
"OpticTygre" <optictygre@adelphia.net> schrieb:
> Alright, so I'm messing around with some code, and I
> brought up a good question to myself.
>
> If creating a class called "Person", and filling that class with
variables,
> properties like:
>
> Public Class Person
> Private mstrName As String
> Private mdtBirthDate As Date
>
> Public Property Name() As String
> Get
> Return mstrName
> End Get
> Set(ByVal Value As String)
> mstrName = Value
> End Set
> End Property
>
> etc......
>
> What is the benefit of typing out all that code over defining a simple
> structure such as:
>
> Structure Person
> Public Name As String
> Public BirthDate As Date
> End Structure
Using properties instead of public variables has the advantage that you can
add code that checks a property's value when it is set. In addition to
that, properties should be used to model "attributes" of an entity (class).
Structures only make sense when their size is small (they are value types
opposed to classes which are reference types), or when it is important to
make them persistent more easily. In this particular case I would prefer a
class over a structure.
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
- Next message: OpticTygre: "Re: Classes, Properties, and structures"
- Previous message: Herfried K. Wagner [MVP]: "Re: declaration expected was unexpected"
- In reply to: OpticTygre: "Classes, Properties, and structures"
- Next in thread: OpticTygre: "Re: Classes, Properties, and structures"
- Reply: OpticTygre: "Re: Classes, Properties, and structures"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|