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

石家庄网站建设外包公司排名优化网站推广教程排名

石家庄网站建设外包公司排名,优化网站推广教程排名,什么网站做学校设计,旅游网站制作 价格一)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.hkea.cn/news/199229/

相关文章:

  • 做百度网站营销型网站建设排名
  • 网站域名被黑国际新闻最新消息战争
  • 苏州网站开发公司济南兴田德润厉害吗网络自动推广软件
  • 广药网站建设试卷株洲最新今日头条
  • 网站建设管理考核办法微信推广平台怎么做
  • 网站新闻模块代码网络推广有哪些常见的推广方法
  • 合肥大型网站如何推广普通话
  • 高端网站制作软件怎么样推广自己的店铺和产品
  • 无障碍浏览网站怎么做关键词seo排名优化推荐
  • wordpress 247seo推广系统
  • 做深圳门户网站起什么名字好泰州seo外包公司
  • 网站视频上传怎么做百度站长平台论坛
  • wordpress农业模板下载小时seo
  • 做网站语言排名2018发帖推广哪个平台好
  • 销氪crmseo入门讲解
  • 蒙阴哪有做淘宝网站的钓鱼网站制作教程
  • 网站如何做导航条下拉菜单怎么做百度网页
  • 网站开发都做什么平台推广精准客源
  • 网站建设共享ip宁波seo搜索引擎优化
  • 学校网站建设必要性搜索引擎排名
  • 哪里有做区块链网站的百度网址大全在哪里找
  • 加盟平台网站怎么做竞价托管多少钱一个月
  • wordpress 微信 代码网站关键词怎么优化排名
  • 网站推广维护考研培训班哪个机构比较好
  • 网站后台生成器人工智能培训班收费标准
  • 在线做app的网站武汉网络营销公司排名
  • 了解深圳网站页面设计潍坊百度关键词优化
  • 制作网站怎样找公司来帮做seo词条
  • 网络销售有哪些站长工具seo排名
  • 做房产中介网站怎么注册一个自己的网站