K
keithv
I'm looking at a bunch of code which has lots of class
fields converted into properties with just the simplest code:
private int empID;
public int empID {
get { return empID; }
set { empID = value; }
}
My question is, isn't this useless and inefficient?
I can't see any benefit to this form of encapsulation over
just making the field public. Later, if you do want to add
some checking or whatever, you can just change the class
to make the field private and add the accessor/mutator
code w/o changing the code which uses the class.
The downside to using properties is efficiency. Every access
to this property is now a function call. It's also annoying
while single-stepping in the debugger, especially code like
"foo(joe.empID);" because you're forced to step into the
accessor code.
Is there some benefit that I'm missing, perhaps dealing
with inter-language issues?
Keith
fields converted into properties with just the simplest code:
private int empID;
public int empID {
get { return empID; }
set { empID = value; }
}
My question is, isn't this useless and inefficient?
I can't see any benefit to this form of encapsulation over
just making the field public. Later, if you do want to add
some checking or whatever, you can just change the class
to make the field private and add the accessor/mutator
code w/o changing the code which uses the class.
The downside to using properties is efficiency. Every access
to this property is now a function call. It's also annoying
while single-stepping in the debugger, especially code like
"foo(joe.empID);" because you're forced to step into the
accessor code.
Is there some benefit that I'm missing, perhaps dealing
with inter-language issues?
Keith