Re: Design question
From: dar7yl (no_reply_at_accepted.org)
Date: 02/26/05
- Next message: Anthony Borla: "Re: send email using JavaMail questions"
- Previous message: el goog: "Re: SortedSet faster than Collections.sort()"
- In reply to: jonck: "Design question"
- Next in thread: Dave Neuendorf: "Re: Design question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 26 Feb 2005 03:27:10 GMT
"jonck" <jonck@vanderkogel.net> wrote in message
news:1109357343.516807.318900@g14g2000cwa.googlegroups.com...
> Hi,
> I have been struggling with this for days now, but it does not look
> like I'm going to figure it out. Here is the situation:
>
> I have a class that stores values that it read in from a database, lets
> call this class Storage. I display this data using a JPanel (which I
> will call DisplayPanel) with several JTextFields, JComboBoxes, JPanel's
> with pictures drawn on them, etc... So in other words, when the user
> selects a new record, the DisplayPanel loads in a new Storage class,
> and calls all the getters of Storage, something like this:
> getFirstNameTextField().setText(storage.getFirstName());
> getLastNameTextField().setText(storage.getLastName());
> getPicturePanel().drawPicture(storage.getPicture());
>
> etc...
>
> Now this is all fine, but now comes the time when the user has made
> some changes and I want to store those back into the Storage class.
> I now have to do the same thing again, but this time in reverse:
> getStorage().setFirstName(getFirstNameTextField().getText());
> getStorage().setLastName(getLastNameTextField().getText());
> getStorage().setPicture(getPicturePanel().getPicture());
>
> etc...
>
> Now there are about 20 fields per Storage class and I have about 10
> different types of Storage classes, so it seems kind of wasteful, very
> non-OOP and error-prone to be doing it as I described above. It seems
> like a pointer would be really useful here, so that I could just pass
> the pointer as the model value to the view, and then when the view is
> updated, the view can update the model, of which it has the pointer.
> But since Java is a pass-by-value language this won't work for me.
>
> Does anyone have any suggestions what a better way of doing things
> might be in the above described situation?
>
> Thanks, Jonck
>
Whatever gave you the idea that Java is pass-by-value?
As far back as I can remember, it has been pass-by-reference
for all object parameters.
You can even consider all object variables to be pointers.
(although you can't perform pointer arithmetic like C/C++)
<code>
Object obj = new Object();
otherobj.method(obj); // obj is not copied, but passed by reference
</code>
so you could try:
<code>
class DisplayPanel extends Panel
{
String getFirstName()
{
return getFirstNameTextField().getText();
}
// ... more accessors
void storeBack( Storage store )
{
store.setFirstName( getFirstName() );
// ...
}
}
</code>
or
- Next message: Anthony Borla: "Re: send email using JavaMail questions"
- Previous message: el goog: "Re: SortedSet faster than Collections.sort()"
- In reply to: jonck: "Design question"
- Next in thread: Dave Neuendorf: "Re: Design question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|