Clojure模型 - 视图 - 控制器(MVC)设计 [英] Clojure Model-View-Controller (MVC) design

查看:146
本文介绍了Clojure模型 - 视图 - 控制器(MVC)设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java Swing在Clojure中编写了一个Desktop GUI应用程序。通常当使用Java时,我将使用Observer模式根据MVC设计模式设计应用程序。这样,视图与模型解耦,并且两者中的更改不会相互影响,从而使更改更容易进行。

I am writing a Desktop GUI application in Clojure using Java Swing. Normally when working with Java I will design the application according to a MVC design pattern using the Observer pattern as well. This way the view is decoupled from the model and changes in either do not affect each other, making changes easier further along.

我想知道Clojure是否比正常的MVC和Observer设计模式有更好的方法来解决这个问题?我是新的函数式编程,所以我不知道如何使模型从视图分离。我需要这个,因为应用程序将被迭代开发,可能有更具挑战性的要求进一步下来。

I was wondering if Clojure has a better approach to this problem than normal MVC and Observer design pattern? I'm new to functional programming so i'm not sure how I can make the model separate from the view. I require this as the application will be developed iteratively and there may be challenging requirements that come along further down the line.

感谢任何帮助。

感谢,

Adam

推荐答案

当你有第一顺序函数,宏(代码作为数据)和并发持久数据结构时,来自java MVC世界的许多设计模式会有点傻。例如观察者模式基本上只是一些手表设置的代理。它从一个模式到一个函数调用。

A lot of the design patterns from the java MVC world get a bit silly when you have first order functions, macroes (code-as-data), and concurrent persistent data structures. for instance the "observer pattern" is basically just an agent with some watches set. It goes from being a pattern to a function call.

如果将状态(模型)存储在ref或代理中,并使您的视图成为显示该状态的函数(在函数的编程意义上)同时使你的控制器一个函数(再次在词的FP意义),产生一个新的状态给定的旧状态和一些新的输入,然后MVC模型非常漂亮。

if you store the state (model) in a ref or agent and make your view a function (in the functional programming sense of the word) that displays that state; while making your controller a function (again in the FP sense of the word) that produces a new state given the old state and some new input then the MVC model falls out very nicely.

有点过时,但Stuart Sierra的网格袋子布局帖子真的帮助我在这一领域开始。

it s bit dated, but Stuart Sierra's grid bag layout post really helped me get started in this area.

这篇关于Clojure模型 - 视图 - 控制器(MVC)设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆