重点:
1.用户通过界面操作,传输到control,control可以直接去处理View,或者通过模型处理业务逻辑,然后将数据传输给view。
2.control包含了model和view成员。
链接:
MVC框架详解_mvc架构-CSDN博客
MVC架构图如下:
#include <iostream>
#include <vector>using namespace std;//Model数据处理器
class Model
{
public:void Increace(){count++;}void Decreace(){count--;}int GetCount(){return count;}void SetCount(int num){count=num;}
private:int count{10};
};//view显示器
class View
{
public:void Update(int data){cout << data << endl;}
};//Controller控制器
class Controller
{
public:Controller(shared_ptr<Model> model, shared_ptr<View> view) :m_model(model), m_view(view){}void HandleIncrementPressed(){m_model->Increace();m_view->Update(m_model->GetCount());}void HandleDecrementPressed(){m_model->Decreace();m_view->Update(m_model->GetCount());}
private:shared_ptr<Model> m_model;shared_ptr<View> m_view;
};int main()
{shared_ptr<Model> model= make_shared<Model>();shared_ptr<View> view = make_shared<View>();shared_ptr<Controller> cont = make_shared<Controller>(model, view);cont->HandleDecrementPressed();cont->HandleIncrementPressed();return 0;}