On Thu, 13 May 2004 15:58:38 +0100, "Dave W"
<DaveWalker*SPAM*skydivers.co.uk> wrote (more or less):
Im looking for an example of OO. The more basic the better! ;)
Maybe i should have gone into more detail. I want to see how 2 classes can
work together. Taking advatange of get & set.
I've tried search the net for example .java files that already exsist, but
to no joy.
The advantage of set and get accessor functions is that they can
control access to the variables possessed by a class.
e.g.
public class Name
{
private String firstName;
private String surname;
public void setSurname(String s)
{ surname = s;
}
public String getSurname()
{ return surname;
}
public void setFirstName(String s)
{ firstName = s;
}
public String getFirstName()
{ return firstName;
}
}
public class PatientAdmin
{
private Name aPatient;
public void enterPatientName(String name1, String name2)
{ aPatient.setSurname(name2);
aPatient.setFirstName(name1);
}
}
Which is not terribly interesting, until it comes time that you want
to incorprate some additional validation routines to the
setSurname(aString).
Making sure that every class that changes the surname does so through
the Name.setSurname(aString) method means that you only ever need to
change one piece of code, and the new validation gets used everywhere
that a surname is amended.
--
Cheers,
Euan
Gawnsoft:
http://www.gawnsoft.co.sr
Symbian/Epoc wiki:
http://html.dnsalias.net:1122
Smalltalk links (harvested from comp.lang.smalltalk)
http://html.dnsalias.net/gawnsoft/smalltalk