Something like the following is probably the simplest example:
However, as it stands, that's not very useful. The whole point of patterns is that they are not just pre-built code libraries. So to give a sensible code example for you, we really need to know a bit more about your application. Can you tell us a bit more about what you need ?
Frank, Thanks for the sample code. All what I need is to show my students a working sample code to demonstrate MVC pattern. I cannot see complete decoupling between those 3 layers in the sample code,would you please modified that codes in a way where I can see MVC better? Usually the start point is the view...right?I mean I will put main() method there? We have lots of discussing about MVC and seems to me we cannot see it very well,please any possible clear explanation? Thanks.
Joined: Jan 07, 1999
Well I'm still waiting to learn a bit more about your application. All you have told me is that you want to start it from "main". This tends to imply that it's not a servlet or applet based example you are looking for, as they don't have a "main". Please tell us more about what context you are thinking of applying this pattern in. In the meanwhile, if you are more concerned about decoupling, consider this slightly more elaborate example:
I've tested it so I know it will compile. Save the code block as "Application.java", Compile it with "javac Application.java", and run it with "java Application". At the prompt, you can type one of the following commands:
X :- to exit the calculator
A :- to add a new view. The controller can have as many views as you like.
R followed by a number :- to remove the numbered view
+ followed by a number :- to add the number to the stored value
- followed by a number :- to subtract the number from the stored value
= to refresh all the views
try the following sequence, as an example
Does this offer any more help in understanding how MVC can help with decoupling?
Joined: May 16, 2002
Frank, Thanks alot for your time to develop that,i will study the code and let you know. Thanks.