Re: Why use properties?
From: James Curran (JamesCurran_at_mvps.org)
Date: 12/03/04
- Next message: Just Me: "I have no idea how to write an HDROP"
- Previous message: Peter Rilling: "Re: ArrayList and System.Array ?"
- In reply to: Janaka: "Re: Why use properties?"
- Next in thread: Jon Skeet [C# MVP]: "Re: Why use properties?"
- Reply: Jon Skeet [C# MVP]: "Re: Why use properties?"
- Reply: Paul E Collins: "Re: Why use properties?"
- Reply: Tom Porterfield: "Re: Why use properties?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 3 Dec 2004 12:13:10 -0500
Funny thing is --- I was just about to post a very similar question to the
group.
However, I'm still a bit more skeptical. Of all the answers given, only
Nicholas's held water.
All the rest boil down to, "You need a property -- if you need more than
simple assignment."
But the question was, "what's the advantage of a property if all I need (for
now) is simple assignment?".
Saying
private int salesTotal;
public int SalesTotal
{
get {return salesTotal;}
set {salesTotal=value;}
}
is better than
public int SalesTotal;
because I might want to change the get/set at some time in the future is a
false lead, as I could convert the latter into the former at any time.
Basically, it comes down to doing more typing now, to potentially save the
same amount of typing later. By the same principle which leads us to
lazy-loading information from databases, would lead us to prefer the public
variable until such time as we need to convert it to a Property.
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Janaka" <janakaf@hotmail.com> wrote in message
news:ewyfUGV2EHA.3596@TK2MSFTNGP12.phx.gbl...
> Thanks for all the replies.
>
> I believe the main reason why to code in a skeleton property with just a
> get/set is to provide future-proofing and easier maintenance in the long
> run.
>
> Tom your reply was even approved by our head sceptic.
> public int SalesTotal;
> >
> > rather than
> >
> > private int salesTotal;
> > public int SalesTotal
> > {
> > get {return salesTotal;}
> > set {salesTotal=value;}
> > }
> >
>
>
- Next message: Just Me: "I have no idea how to write an HDROP"
- Previous message: Peter Rilling: "Re: ArrayList and System.Array ?"
- In reply to: Janaka: "Re: Why use properties?"
- Next in thread: Jon Skeet [C# MVP]: "Re: Why use properties?"
- Reply: Jon Skeet [C# MVP]: "Re: Why use properties?"
- Reply: Paul E Collins: "Re: Why use properties?"
- Reply: Tom Porterfield: "Re: Why use properties?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|