R
RSH
I was reading a tutorial on OOP principals and design and I stumbled on
something that I don't understand. The tutorial used a Oven class. In that
class there was a private field called temperature.
class Oven {
private int _temperature;
public int Temperature {
get {
return _temperature;
}
set {
_temperature = value;
}
}
}
This is the implementation I would normally employ. BUT... The article
says...
"The type Oven exposes its temperature as a property, which is a direct
reference to the variable _temperature. This means that the internal oven
temperature implementation is tied directly to its external interface. The
point of good object-oriented programming is to avoid this sort of
programming."
That seems strange to me...what if I have to expose temperature? What if my
cookie object needs to preheat the oven to 350 degrees dont I need to
monitor the temperature of the oven object?
Damn just when I started to think I was getting OOP!
Thanks,
Ron
something that I don't understand. The tutorial used a Oven class. In that
class there was a private field called temperature.
class Oven {
private int _temperature;
public int Temperature {
get {
return _temperature;
}
set {
_temperature = value;
}
}
}
This is the implementation I would normally employ. BUT... The article
says...
"The type Oven exposes its temperature as a property, which is a direct
reference to the variable _temperature. This means that the internal oven
temperature implementation is tied directly to its external interface. The
point of good object-oriented programming is to avoid this sort of
programming."
That seems strange to me...what if I have to expose temperature? What if my
cookie object needs to preheat the oven to 350 degrees dont I need to
monitor the temperature of the oven object?
Damn just when I started to think I was getting OOP!
Thanks,
Ron