MVC架构

  1. 控制器和视图绑定在一起
  2. 视图识别出了GUI动作,比如说,按下一个键或者下拉滚动条,当动作发生时,被注册的监听方法就会被调用。视图就会调用控制器上合适的方法,然后控制器进入模型,根据用户的动作以合适的方式更新模型。
  3. 如果模型被触发,他会通知所有相关的监听者,比如说视图,在一些架构里,控制器也会负责更新视图
  4. 在这里插入图片描述
  5. 正如前文所说,模型中并没有带有视图的引用,而是使用事件通知的方式来通知改变,这个强有力的设计,许多视图都有潜在的模型。当模型中数据发生改变时,视图都会被相应的属性改变触发,并更新。
  6. The primary difference between this design and the more traditional version of MVC is that the notifications of state changes in model objects are communicated to the view through the controller. Hence, the controller mediates the flow of data between model and view objects in both directions.
  7. This way, whenever a model changes its state, the propertyChange() method is called and the controller will pass this event on to the appropriate views.
  8. In order to keep the models completely decoupled from the controller, the code samples in this article have employed the Java Reflection API.(为了让模型与控制器完全解耦,代码样例使用了java反射机制)In this case, when this method is called with the desired property name, you hunt through the registered models to determine which one contains the appropriate method. Once you find it, you invoke the method using the new value. If the method is not called, the getMethod() will throw a NoSuchMethodException, which the exception handler ignores, allowing the for- loop to continue.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值