Java MVC &具有内部框架的复合设计模式
仍然想知道模型-视图-控制器软件架构的最佳方法,是将控制器传递到视图中,还是使用观察者设计模式并让控制器观察视图所做的任何更改/请求,以便我们可以更新模型并重新显示......
我有一个主 JFrame,它将有 JInternalframes,并且我想应用 MVC 架构。仅使用普通的 Java 应用程序
任何关于限制等的建议都会有很大帮助。
抱歉,造成混乱,不是有一个仅使用框架和内部框架的网络方面吗?
Still wondering the best way to do Model-View-Controller Software Architecture, Do I pass the Controller into the View, or do I use the Observer Design Pattern and let the Controller Observe any changes/requests made by the view so we can update the model and redisplay that.......
I have A Main JFrame which will have JInternalframes, and i want to apply the MVC Architecture. Using just a normal Java Application
Kind of stuck on this any suggestions to limitations ect will help a lot.
Sorry For the confusion, didn't there was an web aspect that just uses Frame and Internal Frame
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我去年用MVC模式编写了一个程序,但我似乎找不到代码atm,我记得我将它与观察者模式一起使用,以便控制器监听视图(因此控制器实现了观察者,视图实现 Observable)
(注意:我还是一名学生,所以我的评论中可能有一些错误......只是想提供帮助!)
I have written a program with the MVC pattern last year but I can't seem to find the code atm, I DO recall that I used it with the observer pattern, so that the Controller listened to the View (so controller implements Observer, view implements Observable)
(note: I'm still a student so there may be some errors in my comments.. just trying to help though!)
您的大型机包含所有框架,因此可以访问它们。
内部框架应该在构造函数中获取其“父亲”框架作为参数,并将其存储为上下文变量。
这样您就可以同时使用两者:如果您决定传递控制器(MainFrame),视图(InternalFrames)可以注册其事件,或者您可以通过控制器更新视图。
关于您的问题,您应该使用观察者设计模式。
这在逻辑上是正确的,让控制器控制流程并在模型更改时更新视图。
Your Mainframe contains all the frames, therefore they are accessible to it.
The internal frames should get their "father" frame in the constructor as a a parameter, and store it as a context variable.
That way you can use both: if you decide to pass controller (MainFrame), views (InternalFrames) can register on its event, or you can update view through your controller.
regarding your question , you should use the Observer Design Pattern.
this is logically correct to let the Controller control the flow and update the view upon model change.