Created
August 7, 2017 14:14
-
-
Save lexuanquynh/210813335977a16f367055078faf2c04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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