MVC approach with C++

前端 未结 6 825
鱼传尺愫
鱼传尺愫 2020-12-13 04:41

I have been learning PHP MVC pattern and it is pretty cool. have almost finished app and I can see how mess you can make a code without good design. Now can MCV be applied t

6条回答
  •  旧巷少年郎
    2020-12-13 05:33

    how do you actually implement it in C++

    • make classes in charge of rendering know nothing about application details. Call them SomethingView classes to make this point clear

    • make your domain objects not know anything about visualization or user interaction. You don't need to call them Model, but you could

    • create a set of classes in charge of running the role of Controllers: wire somehow dependencies to view and model classes via dependency injection if possible. example: CppInject. In any case, controller classes can know both about model and view classes, so the important part is this: all the coupling between view and model objects is isolated to the controllers.

    • Also, this implies, that all imperative-style programming should be confined to the controller classes as well: view and model should be declarative-style. That means, they should offer services related to its role, but avoid direct interaction with other objects as side-effects

    • It is not true you need to implement communication between controllers and the other components with event-style system, although such system is definitely helpful, but certainly not required

    • surprise! the above applies to any language or framework, except of course languages that somehow already force MVC down your throat from the start, i.e: ruby on rails

提交回复
热议问题