重点:
1.用户通过界面操作,传输到control,control可以直接去处理View,或者通过模型处理业务逻辑,然后将数据传输给view。
2.control包含了model和view成员。
链接:
MVC框架详解_mvc架构-CSDN博客
MVC架构图如下:
#include #include 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, shared_ptr 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 m_model; shared_ptr m_view; }; int main() { shared_ptr model= make_shared(); shared_ptr view = make_shared(); shared_ptr cont = make_shared(model, view); cont->HandleDecrementPressed(); cont->HandleIncrementPressed(); return 0; }