当前位置: 首页 > news >正文

网站cms系统 开源网站推广的策略

网站cms系统 开源,网站推广的策略,网站的技术解决方案,微信公众号登录wordpress网站一)Model - View - Presenter (MVP) 模式在 TouchGFX 中的应用 1)Model(模型): 模型代表应用程序的数据和业务逻辑。例如,在一个简单的计数器应用中,模型可以是一个包含计数器当前值的类。 class CounterModel { pri…

一)Model - View - Presenter (MVP) 模式在 TouchGFX 中的应用
1)Model(模型):
模型代表应用程序的数据和业务逻辑。例如,在一个简单的计数器应用中,模型可以是一个包含计数器当前值的类。

class CounterModel 
{
private:int count;
public:CounterModel() : count(0) {}int getCount() const {return count;}void increment() {count++;}
};

2)View(视图):
在 TouchGFX 中,视图是通过界面设计工具创建的图形用户界面(GUI)元素。例如,有一个文本框用于显示计数器的值,一个按钮用于增加计数器的值。这些 GUI 元素在 TouchGFX Designer 中设计,然后在代码中通过相关的类来引用。
视图类需要能够更新界面显示,以反映模型的状态变化。以下是一个简单的视图类示例,用于显示计数器的值:

class CounterView : public touchgfx::View{
private:touchgfx::TextAreaWithOneWildcard& countText;
public:CounterView(touchgfx::TextAreaWithOneWildcard& textArea) : countText(textArea) {}void updateCounterDisplay(int count){Unicode::snprintf(countText.getBuffer(), countText.getBufferSize(), "%d", count);countText.invalidate();}
};

3)Presenter(展示器):
展示器作为模型和视图之间的桥梁,它包含对模型和视图的引用,并处理用户交互。当用户点击增加计数器的按钮时,展示器会调用模型的increment方法来更新数据,然后调用视图的updateCounterDisplay方法来更新界面。

class CounterPresenter 
{
private:CounterModel& model;CounterView& view;
public:CounterPresenter(CounterModel& m, CounterView& v) : model(m), view(v) {}void handleIncrementButtonClicked() {model.increment();view.updateCounterDisplay(model.getCount());}
};

使用示例:
在main函数或者应用程序初始化的地方,可以这样使用 MVP 模式构建计数器应用。
// 创建模型、视图和展示器

CounterModel counterModel;
touchgfx::TextAreaWithOneWildcard countTextArea;
CounterView counterView(countTextArea);
CounterPresenter counterPresenter(counterModel, counterView);

// 假设这里有一个按钮点击事件处理器,将其与展示器的方法关联
Button incrementButton;
incrementButton.setClickAction(counterPresenter, &CounterPresenter::handleIncrementButtonClicked);
二)Model - View - Controller (MVC) 模式在 TouchGFX 中的应用示例(与 MVP 类似但有区别)
1)Model(模型):
同样以计数器应用为例,模型类和 MVP 模式中的类似。

class CounterModel{
private:int count;
public:CounterModel() : count(0) {}int getCount() const{return count;}void increment() {count++;}
};

2)View(视图):
在 MVC 模式中,视图主要负责显示。它会从模型获取数据来更新自己的显示,但不像 MVP 中的视图那样直接被展示器调用更新方法。

class CounterView : public touchgfx::View 
{
private:touchgfx::TextAreaWithOneWildcard& countText;
public:CounterView(touchgfx::TextAreaWithOneWildcard& textArea) : countText(textArea) {}void updateCounterDisplay(int count){Unicode::snprintf(countText.getBuffer(), countText.getBufferSize(), "%d", count);countText.invalidate();}
};

3)Controller(控制器):
控制器处理用户输入和模型更新,同时也会通知视图更新显示。与 MVP 不同的是,它的职责划分更侧重于控制整个流程。

class CounterController{
private:CounterModel& model;CounterView& view;
public:CounterController(CounterModel& m, CounterView& v) : model(m), view(v) {}void handleIncrementButtonClicked() {model.increment();view.updateCounterDisplay(model.getCount());}
};

使用示例:
与 MVP 模式类似,在应用程序初始化阶段使用 MVC 模式构建计数器应用。
// 创建模型、视图和控制器
CounterModel counterModel;
touchgfx::TextAreaWithOneWildcard countTextArea;
CounterView counterView(countTextArea);
CounterController counterController(counterModel, counterView);

// 假设这里有一个按钮点击事件处理器,将其与控制器的方法关联
Button incrementButton;
incrementButton.setClickAction(counterController, &CounterController::handleIncrementButtonClicked);
这些设计模式有助于将 TouchGFX 应用程序的不同职责分离,使得代码更加模块化、易于维护和扩展。在实际应用中,可以根据具体的项目需求选择合适的设计模式。

http://www.yidumall.com/news/44904.html

相关文章:

  • 拱墅区做网站重庆百度推广开户
  • 汕头站扩建招标百度客服人工电话
  • 郑州网站设计的公司百度关键词查询网站
  • 专注邯郸建设手机网站app拉新推广怎么做
  • asp做的网站如何发布seo优化及推广如何运营
  • 网站建设 图片百度推广手机客户端
  • 四川超宇建设集团网站免费公司网站建站
  • 网站开发阶段怎么做测试搜索引擎优化网站排名
  • 关于公司网站建设情况的汇报百度今日排行榜
  • 怎么做网站一张图论坛推广方案
  • 星光影视园网站建设案例上海网站seo策划
  • 电子商务网站建设的概要设计博客优化网站seo怎么写
  • 浙江网站建设公司电话公司全网推广
  • 在线播放的网站怎么做技术短期培训班
  • 黑龙江省住房和城乡建设厅网络优化工程师
  • 做海报挣钱的网站盘多多搜索引擎入口
  • WordPress全站广告广东东莞疫情最新情况
  • 免签约收款WordPress优化神马排名软件
  • 云虚拟主机怎么建网站谷歌推广费用多少
  • 做产品网站要备案吗查淘宝关键词排名软件
  • 游戏网站策划营销策划方案ppt模板
  • 网站建设项目背景宁波网站优化公司哪家好
  • 百度官方下载seo的概念是什么
  • 为什么做织梦网站时图片出不来seo排名点击软件推荐
  • 建自己的网站用多少钱头条权重查询
  • 在自己电脑建设网站大型营销型网站制作
  • 做网站学生作业百度灰色关键词代发
  • 什么是静态网页佛山seo培训
  • 江门企业网站建设营业推广策略
  • 怎么做html5网站吗企业站seo案例分析