Hi Kim,
It's a matter of good OO practice and future-proofing.
At the moment, you may believe that all you are doing is
getting and
setting. Then, one day, you find out, say, that invalid
data is being
passed to your setter. Because it's a method, you can
easily change it
to include some validation. You can't do that if you're
just setting a
public field, and adding a method later and trying to find
all the code
that will be broken by your, now, private property is a real
nightmare.
So the advice is, "Just don't do it". Make all
your fields private (or
possibly protected) and provide appropriate mutator methods.
Even when
you're just playing. It's like using the indicators on
your car. If
you always use them, even when not strictly necessary, you
won't fail to
use them when it is really necessary.
And don't let anyone worry you about execution speed. If
you were
worried about execution speed you wouldn't be using an OO
language, and
especially not one that relies on a VM. Just don't try to
write an
operating system in C#
Just my 2c (dwy geiniog) of course and YMMV.
Peter
-----Original Message-----
From: CSDevelopers googlegroups.com
[mailto:CSDevelopers googlegroups.com] On Behalf Of kim
Sent: 23 June 2006 12:27
To: C# Developers
Subject: Re: arraylist
Bradley, Peter wrote:
>
> And yes, I am implying that you should change to
properties, with
> appropriate accessors, and not use public instance
variables
>
Seems like a clever idea, but it is not clear to me why I
should if I
am only going to get and set.
Regards,
Kim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C# Developers" group.
To post to this group, send email to CSDevelopers googlegroups.com
To unsubscribe from this group, send email to
CSDevelopers-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/CSDevelopers
-~----------~----~----~----~------~----~------~--~---
|