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

数字货币网站开发h5响应式企业网站源码

数字货币网站开发,h5响应式企业网站源码,网站的类型主要有,重庆建设工程管理网一)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.yayakq.cn/news/744259/

相关文章:

  • 如何做竞价网站数据监控云主机免费
  • 网站建设创意文案百度安装应用
  • 网站建设进度及实施过程礼品网站建设公司
  • 优秀的定制网站建设制作商wordpress 新建数据库
  • 网站建设流js做网站跳转
  • 河北中冶润丰建设股份有限公司网站网站方案制作
  • 盘锦网站建设多少钱网站内容页301如何做
  • 临沂营销型网站建设wordpress 4.7
  • 外贸移动端网站模板wordpress 标签链接
  • 个人网站免费域名竞价培训班
  • 深圳网站优化效果温岭高端网站设计哪家好
  • 企业网站源码带后台管理众筹网站建设费用
  • 衡阳市做网站百度推广外包
  • 销售行业怎样做网站网站备案和不备案的区别
  • 南宁网站建设策划外包宁国做网站的
  • 个人建设任务网站门户网站建设方案中信息公开
  • 网站建设就找桥三科技网站建设参考文献作者
  • 工业和信息化部网站备案永兴县网站建设推广公司
  • 哪个网站的课件做的好石景山网站建设公司排行
  • 做网站的手机软件宁波电商网站建设开发
  • 成都装饰公司网站建设海外平台有哪些
  • 有关网站开发的创意手机英文网站大全
  • 建筑工地网站网站制作目标及要求
  • 企业网站销售电商会学着做网站呢
  • 做网站制作一般多少钱腾讯云可以做网站
  • 网站维护哪些贵阳seo网站推广
  • 部队网站模板开发公司五证
  • 男周志做网站完全自定义纯代码打造你的wordpress站点侧边栏
  • 建设银行联号查询网站学字体网站
  • 免费手机端网站模板下载安装公众号wordpress