MVC approach with C++

前端 未结 6 820
鱼传尺愫
鱼传尺愫 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:21

    Yes, MVC can be applied in C++. For example, the MFC framework uses Document/View architecture which is essentially an MVC.

    A design pattern isn't a library or class. It's a pattern. So you don't have a generic MVC library for C++.

    0 讨论(0)
  • 2020-12-13 05:24

    Use Tree frogs Framework. TreeFrog Framework is a high-speed and full-stack C++ framework for developing Web applications.

    0 讨论(0)
  • 2020-12-13 05:24

    Personally, I use boost state machines for the logical and boost signals to connect things together.

    I wrote a little example that you can analyze here: https://github.com/edubois/mvp-player

    0 讨论(0)
  • 2020-12-13 05:26

    MVC is an architectural design pattern (i.e. a way of building software) commonly associated with web applications, but it is applicable in general to any software project in any language. You have to make a little abstraction effort on your project, and identify which piece of software belongs to each part (i.e. a GUI is probably part of View, etc.).

    Note that this type of pattern is mainly aimed to separate developement, so that any part of the project can be developed regardless of the others. This can be annoying for a small standalone application, but useful and rewarding on bigger projects.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-13 05:40

    MVC is a design pattern not a language specific construct, So yes you can apply it to C++ app as well.

    MVC can and should be applied in any language so your User Interface is loosely coupled with the backend & either can be changed with minimum impact on each other.

    The MVC pattern provides a clean separation of objects into:

    • Models for maintaining data,
    • Views for displaying all or a portion of the data, and
    • Controllers for handling events that affect the model or view(s).
    0 讨论(0)
提交回复
热议问题