Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

model view controller - MVC approach with C++

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 to C++ apps? Where does Plugin manager/Plugins go if that is even possible?In model or controller? Thanks!

EDIT:

I mean C++ with GUI toolkit like QT/Wxwidgets/GTK+ Also Please help me on how to implement in C++. I have learned how to do it in PHP but as you know the two languages are somehow different!

EDIT2

http://forums.wxwidgets.org/viewtopic.php?f=1&t=30983

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...