What's the best way to acess the model from the view in a MFC approach?

C

***C.Steamer***

Say I got a class that extends JPanel and I want to update the model class
from within the JPanel class, what is the best way to do that. I already
implement an Observer pattern to update the GUI from the model but how do we
go the other way. Basically I will be clicking on an area of the panel and
based on which object I select I want to change something in the model
class. Should I just pass in all the classes that the GUI will need? I don't
like this method cuz then you have to have the classes already instantiated
before you build the gui and it makes for intermixed code. Or should I make
the model class into Singleton so I can statically access the class from
anywhere? Thanks for your help?
 
D

------Dacleaver------

***C.Steamer*** said:
Say I got a class that extends JPanel and I want to update the model class
from within the JPanel class, what is the best way to do that. I already
implement an Observer pattern to update the GUI from the model but how do
we go the other way. Basically I will be clicking on an area of the panel
and based on which object I select I want to change something in the model
class. Should I just pass in all the classes that the GUI will need? I
don't like this method cuz then you have to have the classes already
instantiated before you build the gui and it makes for intermixed code. Or
should I make the model class into Singleton so I can statically access
the class from anywhere? Thanks for your help?
Ops, I mean the MVC approach not the MFC. Sorry
 
T

Thomas Weidenfeller

***C.Steamer*** said:
Say I got a class that extends JPanel and I want to update the model class
from within the JPanel class, what is the best way to do that.

Do you really expect to get answers after

Message-ID: <Cgzed.40930$z96.9460@clgrps12>

?

Oh, and changing you name doesn't help. But when you do, consider
removing the "I-am-cleaver". It also doesn't help to post to the wrong
group (well after the above referenced post it also won't help you to
post to the right one) and it doesn't help using slang like "cuz". Trust
us, you don't look cool.

/Thomas
 
J

Jacob

***C.Steamer*** said:
Say I got a class that extends JPanel and I want to update the model class
from within the JPanel class, what is the best way to do that. I already
implement an Observer pattern to update the GUI from the model but how do we
go the other way.

Basically you do by direct access. The GUI modules should
have references to the model counterparts. Note also that
any events that should be produced should be invoked from
the GUI making the changes, and *not* from the model itself.
Should I just pass in all the classes that the GUI will need? I don't
like this method cuz then you have to have the classes already instantiated
before you build the gui and it makes for intermixed code.

In principle the GUI should have references to the model
classes, but if performance is at stake you should consider
replacing the actual model objects with empty proxy objects.
These will have a name, a location in the overall model
hierarchy and an ability to *load* themselves (possibly
through some accessor interface). From the user point of
view it will appear as the real object. When the actual
data is needed they are instantiated lazily.
 
A

Alex Hunsley

***C.Steamer*** said:
Say I got a class that extends JPanel and I want to update the model class
from within the JPanel class, what is the best way to do that. I already
implement an Observer pattern to update the GUI from the model but how do we
go the other way. Basically I will be clicking on an area of the panel and
based on which object I select I want to change something in the model
class. Should I just pass in all the classes that the GUI will need? I don't
like this method cuz then you have to have the classes already instantiated
before you build the gui and it makes for intermixed code. Or should I make
the model class into Singleton so I can statically access the class from
anywhere? Thanks for your help?

What makes you think you're going to get any help here after this
disgraceful performance? http://makeashorterlink.com/?J1B114F99

(which was in response to helpful information from myself.)

Now, go away.
 
A

Alex Hunsley

Jacob said:
Basically you do by direct access. The GUI modules should
have references to the model counterparts. Note also that
any events that should be produced should be invoked from
the GUI making the changes, and *not* from the model itself.

[snip]
Jacob - I'd wouldn't answer this buffoon if I were you. He isn't very
grateful for help: http://makeashorterlink.com/?J1B114F99
 
A

Alex Hunsley

jacob said:
I judge the content only.

How do you judge this content then:

(OP wrote:)
Yeah thanks for nothing dude, If you don't have anything useful to add
don't say anything.

Or do you think that because this comment doesn't involve java, it
doesn't matter at all?

The issue is an important one, and as this is a _forum_
the reply is for everyone.

Yes, and everyone in the "forum" suffers if you send the message that
immature, anti-social and unreasonable behaviour is OK. If the original
poster with the ID10T flag set sees that he can get treated with respect
when he is not showing it for others, then he has no reason to change
his ways, and we retain another deadweight.
 
J

jacob

Alex said:
How do you judge this content then:

(OP wrote:)

Or do you think that because this comment doesn't involve java, it
doesn't matter at all?

This was not from the post to which I was replying;
not even from the same thread. I don't investigate
the posting history to individuals before replying.
And it wouldn't matter anyway.
If the original
poster with the ID10T flag set sees that he can get treated with respect
when he is not showing it for others, then he has no reason to change
his ways, and we retain another deadweight.

I try to treat everyone with respect. If all did,
the quality of the forum could be kept at level.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top