Skip to content

Instantly share code, notes, and snippets.

@lexuanquynh
Created August 7, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lexuanquynh/210813335977a16f367055078faf2c04 to your computer and use it in GitHub Desktop.
Save lexuanquynh/210813335977a16f367055078faf2c04 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
class Model;
class View;
class Controller;
//Model - View - Controller Design pattern
using std::string;
using std::cout;
using std::endl;
class Model {
private:
string mText;
public:
Model() {
}
Model(const string &text) {
setText(text);
}
void setText(const string &text) {
mText = text;
}
string getText() {
return mText;
}
};
class View {
private:
Model mModel;
public:
View() {
}
View(const Model &model) {
mModel = model;
}
void setModel(Model &model) {
mModel = model;
}
void display() {
cout << mModel.getText() << endl;
}
};
class Controller {
private:
Model mModel;
View mView;
public:
Controller(const Model &model, const View &view) {
setModel(model);
setView(view);
}
void setModel(const Model &model) {
mModel = model;
}
void setView(const View &view) {
mView = view;
}
void onLoad() {
mView.display();
}
};
int main() {
Model mModel("Helloworld 8");
View mView(mModel);
Controller mController(mModel, mView);
mController.onLoad();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment