QT 版puremvc框架

PDMvcFramework

MVC介绍

MVC框架

在这里插入图片描述

将应用程序分为Model、View、Controller三个大模块,Model主要负责应用程序的数据持有,View模块负责业务UI展示,Controller模块负责业务逻辑处理。


MVC框架实现

在这里插入图片描述

使用管理类统一管理注册Controller,Controller管理自己的View与Model,在Controller与Controller之间实现事件机制为模块与模块之间通信做桥梁,模块内部Controller可以控制Model与View的逻辑,View响应Controller操作并显示UI,Model由Controller控制,存储数据。


PureMvc框架

在这里插入图片描述


PureMvc

宏观上将应用程序分为Model、Controller以及View三大模块,在模块内以代理的方式将各个模块细分,并以Facade(单例)作为各个细分模块(Mediator、Proxy以及Command)的管理:

  • Model以Proxy作为各个模块数据存储;
  • Meditor代理View组件的行为,发生行为之后发送Notification;
  • Command作为Mediator行为的执行者,将Mediator发送的Notification映射为一个个可执行的Command;

PureMvc通信

在这里插入图片描述

  • 用户操作View,调用Mediator函数
  • Mediator将用户操作以及数据封装,并发送Notification
  • Facade将发送的Notification派发到对应处理的Command
  • Command处理完操作,存储数据(如果有的话),然后发送Notification通知Mediator
  • Mediator收到Notification之后显示View

模块以及细分

View与Mediator

Mediator将View细分模块之后,各个View模块的“UI行为”操作由Mediator代理完成,Mediator是View行为与Controller(大模块)的中介,有View统一管理。

Model与Proxy

Proxy将Model层细分为一个个代理(Proxy),将程序的数据分组,并由Model统一管理。

Controller与Command

Controller统一管理各个Command操作,并且在收到Notification的时候将对应的Notification映射到Command并执行。

Facade与MVC

MVC将三层注册为一个个的单例之后由Facade统一管理MVC三层,Facade作为MVC三层的“门面”,为MVC的子模块提供功能。


观察者模式

在这里插入图片描述

Notification

Notification为观察者模式提供数据行为支持,是观察者模式传递数据的中介,接口如下:

函数参数返回值说明
getNotificationNamevoidQString获取该notification的标识(名字)
getBodyvoidQvaraient返回该notification携带的数据
Observer

Observer作为notification的监听者,是notification行为的执行人,Observer将会被注册到ObserverFacade(HashMap),ObserverFacade在收到Notification的时候从表中取出需要执行的Observer让其执行:

函数参数返回值说明
handleNotificationINotificationvoidnotification调用函数
Notifier

Notification 消息发送者,消息发送者在调用Notification之后,将消息映射到Observer表之后,找出对应的执行者执行Notification:

函数参数返回值说明
sendNotificationNotificationvoidnotification发送函数

Command模式

Command模式映射一个个Notification为具体的执行操作,将Mediator发出的Notification转换为实际的业务逻辑:
在这里插入图片描述

源代码参考地址:https://github.com/HejiangK/PDMvcFramework

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值