-
February 19th, 2008, 03:55 PM
#1
Accessor Methods in .NET
I've been writing an RPG for a while, but started running into problems because I didn't abstract things out correctly. Anyways, I'm rewriting the codebase to be more developer-friendly, but I'm stuck on something.
What is the point of an accessor method, as opposed to simply having a public member? For example, I have a clsSprite class. The class has a Point object to specify the location of the sprite on the game screen. In the original codebase, I had:
Code:
public Point ptLocation = new Point();
What is the advantage of having this instead?:
Code:
private Point ptLocation = new Point();
public int LocationX
{
get
{
return ptLocation.X;
}
set
{
ptLocation.X = value;
}
}
public int LocationY
{
get
{
return ptLocation.Y;
}
set
{
ptLocation.Y = value;
}
}
I know it has something to do with memory management, but it doesn't make much sense to me. This seems like there's just more code to bloat my class. Am I wrong?
Geek isn't just a four-letter word; it's a six-figure income.
Similar Threads
-
By Juridian in forum The Security Tutorials Forum
Replies: 3
Last Post: February 12th, 2006, 04:40 PM
-
By avdven in forum Web Development
Replies: 1
Last Post: July 24th, 2002, 06:18 AM
-
By Mankan in forum Other Tutorials Forum
Replies: 8
Last Post: July 23rd, 2002, 02:43 PM
-
By Negative in forum Other Tutorials Forum
Replies: 13
Last Post: July 11th, 2002, 10:03 PM
-
By jcdux in forum Microsoft Security Discussions
Replies: 0
Last Post: April 12th, 2002, 11:23 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|