By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

Java OO sample

P: n/a
Hi,

Im looking for an example of OO. The more basic the better! ;)

Cheers,
Dave
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Regards,
Dave
Jul 17 '05 #2

P: n/a
Dave W wrote:
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.

Regards,
Dave


Many projects in a Java book or an Java program at
http://www.sourceforge.net should work.

--
Will Twentyman
email: wtwentyman at copper dot net

Jul 17 '05 #3

P: n/a
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
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.