> Why make a member anything other than public anyhow?
Code:
class LifeSupportSystem {
Medicine m;
Timer t;
LifeSupportSystem( Medicine med, int seconds )
{m = new Medicine( med ); t = new Timer( seconds ); }
DeliverDose( ) { System.out.toIV( Medicine.m, Medicine.dose }
Stop( ) { t.seconds = -1; }
}
Ok then. Tell me why all of this should be public? Assume we're writing for an embedded system that controls life support. Since everything is public, what prevents me from overriding the DeliverDose( ), or to override Medicine and change the dose?
myLifeSupporteInstance.m.dose *= 500; //oops
Or stopping their life support by overriding the DeliverDose()?
DeliverDose( ) { Stop( ); }
See, there are very very good reasons to have private members.
Quzah.