Re: Simpler syntax for properties?
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 04/07/04
- Next message: Jeff Gaines: "Re: Visual studio problem with obfuscated libraries!"
- Previous message: The Bear: "Nested Datagrids"
- In reply to: Julie: "Re: Simpler syntax for properties?"
- Next in thread: Daniel O'Connell [C# MVP]: "Re: Simpler syntax for properties?"
- Reply: Daniel O'Connell [C# MVP]: "Re: Simpler syntax for properties?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 7 Apr 2004 20:28:38 +0100
Julie <julie@nospam.com> wrote:
> > If you want to later change the implementation, you can't.
> > If you want to limit access to read or write only, you can't.
> > If you want to validate values on set, you can't.
> > If you want to trace use during debug, you can't.
>
> If I want to later change the implementation, I could simply do this:
>
> private SomeType p; // Was: P
>
> public SomeType P
> {
> get { /* ... */ }
> set { /* ... */ }
> }
>
> That solves 1 and 2, right?
No - you've just broken your public interface, so anything using it
needs to be recompiled. Using properties, the public interface stays
the same even if the implementation changes.
> The OP didn't indicate the need to validate values to trace in debug. If those
> are requirements, then you are right. If not requirements, then what is wrong
> w/ my idea?
The above. If the OP's requirements for tracing, validation etc change
(as they often do), using properties provides a backward-compatible way
of working. Fields don't.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Jeff Gaines: "Re: Visual studio problem with obfuscated libraries!"
- Previous message: The Bear: "Nested Datagrids"
- In reply to: Julie: "Re: Simpler syntax for properties?"
- Next in thread: Daniel O'Connell [C# MVP]: "Re: Simpler syntax for properties?"
- Reply: Daniel O'Connell [C# MVP]: "Re: Simpler syntax for properties?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|