├── src ├── LoginInfo.cpp ├── LoginResult.cpp ├── Patterns │ ├── Command.cpp │ ├── UpdateData.cpp │ ├── Notifier.cpp │ ├── Proxy.cpp │ ├── Notifier.h │ ├── Command.h │ ├── Notification.cpp │ ├── UpdateData.h │ ├── Notification.h │ ├── Proxy.h │ ├── Mediator.cpp │ ├── Mediator.h │ ├── Facade.h │ └── Facade.cpp ├── Interface │ ├── IObserver.h │ ├── INotifier.h │ ├── IViewComponent.h │ ├── IProxy.h │ ├── IUpdateData.h │ ├── ICommand.h │ ├── IMediator.h │ ├── INotification.h │ ├── IView.h │ ├── IModel.h │ ├── IFacade.h │ └── IController.h ├── LoginInfo.h ├── LoginResult.h ├── LoginCommand.h ├── LoginProxy.h ├── main.cpp ├── ApplicationFacade.h ├── LoginCommand.cpp ├── LoginMediator.h ├── ApplicationFacade.cpp ├── Core │ ├── Model.h │ ├── Controller.h │ ├── View.h │ ├── Model.cpp │ ├── Controller.cpp │ └── View.cpp ├── LoginForm.h ├── LoginProxy.cpp ├── login_dialog.ui ├── LoginMediator.cpp ├── LoginForm.cpp └── ui_login_dialog.h ├── README.md └── LICENSE /src/LoginInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "LoginInfo.h" 2 | 3 | LoginInfo::LoginInfo() 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /src/LoginResult.cpp: -------------------------------------------------------------------------------- 1 | #include "LoginResult.h" 2 | 3 | LoginResult::LoginResult() 4 | { 5 | m_updateDataName = "LoginResult"; 6 | } 7 | -------------------------------------------------------------------------------- /src/Patterns/Command.cpp: -------------------------------------------------------------------------------- 1 | #include "Command.h" 2 | 3 | void Command::excute(INotification *notification) 4 | { 5 | 6 | } 7 | 8 | void Command::notifyObserver(INotification *notification) 9 | { 10 | excute(notification); 11 | } 12 | -------------------------------------------------------------------------------- /src/Interface/IObserver.h: -------------------------------------------------------------------------------- 1 | #ifndef IOBSERVER_H 2 | #define IOBSERVER_H 3 | 4 | class INotification; 5 | 6 | class IObserver 7 | { 8 | public: 9 | virtual void notifyObserver(INotification *notification) = 0; 10 | }; 11 | 12 | #endif // IOBSERVER_H 13 | -------------------------------------------------------------------------------- /src/LoginInfo.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGININFO_H 2 | #define LOGININFO_H 3 | 4 | #include 5 | 6 | class LoginInfo 7 | { 8 | public: 9 | LoginInfo(); 10 | 11 | public: 12 | QString name; 13 | QString password; 14 | }; 15 | 16 | #endif // LOGININFO_H 17 | -------------------------------------------------------------------------------- /src/Interface/INotifier.h: -------------------------------------------------------------------------------- 1 | #ifndef INOTIFIER_H 2 | #define INOTIFIER_H 3 | 4 | class QString; 5 | 6 | class INotifier 7 | { 8 | public: 9 | virtual void sendNotification(const QString ¬ificationName, void *body) = 0; 10 | }; 11 | 12 | #endif // INOTIFIER_H 13 | -------------------------------------------------------------------------------- /src/Interface/IViewComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef IVIEWCOMPONENT_H 2 | #define IVIEWCOMPONENT_H 3 | 4 | #include "IUpdateData.h" 5 | 6 | class IViewComponent 7 | { 8 | public: 9 | virtual void update(IUpdateData *updateData) = 0; 10 | }; 11 | 12 | #endif // IVIEWCOMPONENT_H 13 | -------------------------------------------------------------------------------- /src/LoginResult.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINRESULT_H 2 | #define LOGINRESULT_H 3 | 4 | #include "Patterns/UpdateData.h" 5 | 6 | class LoginResult : public UpdateData 7 | { 8 | public: 9 | LoginResult(); 10 | 11 | public: 12 | bool result; 13 | }; 14 | 15 | #endif // LOGINRESULT_H 16 | -------------------------------------------------------------------------------- /src/LoginCommand.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINCOMMAND_H 2 | #define LOGINCOMMAND_H 3 | 4 | #include "Patterns/Command.h" 5 | 6 | class LoginCommand : public Command 7 | { 8 | public: 9 | LoginCommand(); 10 | 11 | void excute(INotification *notification); 12 | }; 13 | 14 | #endif // LOGINCOMMAND_H 15 | -------------------------------------------------------------------------------- /src/LoginProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINPROXY_H 2 | #define LOGINPROXY_H 3 | 4 | #include "Patterns/Proxy.h" 5 | 6 | class LoginInfo; 7 | 8 | class LoginProxy : public Proxy 9 | { 10 | public: 11 | LoginProxy(); 12 | 13 | void checkLogin(LoginInfo *loginInfo); 14 | }; 15 | 16 | #endif // LOGINPROXY_H 17 | -------------------------------------------------------------------------------- /src/Interface/IProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef IPROXY_H 2 | #define IPROXY_H 3 | 4 | class QString; 5 | 6 | class IProxy 7 | { 8 | public: 9 | /** 10 | * Get the name of the IProxy instance. 11 | * @return The IProxy instance name. 12 | */ 13 | virtual QString getProxyName() = 0; 14 | }; 15 | 16 | #endif // IPROXY_H 17 | -------------------------------------------------------------------------------- /src/Patterns/UpdateData.cpp: -------------------------------------------------------------------------------- 1 | #include "UpdateData.h" 2 | 3 | /*QString UpdateData::getType() const 4 | { 5 | return m_updateDataType; 6 | } 7 | 8 | QString UpdateData::setType(const QString &type) 9 | { 10 | m_updateDataType = type; 11 | }*/ 12 | 13 | QString UpdateData::getName() const 14 | { 15 | return m_updateDataName; 16 | } 17 | -------------------------------------------------------------------------------- /src/Patterns/Notifier.cpp: -------------------------------------------------------------------------------- 1 | #include "Notifier.h" 2 | #include "../Interface/INotification.h" 3 | #include "Facade.h" 4 | 5 | Notifier::Notifier() 6 | { 7 | m_facade = Facade::getInstance(); 8 | } 9 | 10 | void Notifier::sendNotification(const QString ¬ificationName, void *body) 11 | { 12 | m_facade->sendNotification(notificationName, body); 13 | } 14 | -------------------------------------------------------------------------------- /src/Patterns/Proxy.cpp: -------------------------------------------------------------------------------- 1 | #include "Proxy.h" 2 | #include "../Interface/IUpdateData.h" 3 | 4 | QString Proxy::PROXY_NAME = "Proxy"; 5 | 6 | QString Proxy::getProxyName() 7 | { 8 | return PROXY_NAME; 9 | } 10 | 11 | /*bool Proxy::registerUpdateData(const QString ®isterDataType, IUpdateData *updateData) 12 | { 13 | 14 | updateData->setType(registerDataType); 15 | }*/ 16 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ApplicationFacade.h" 3 | #include "LoginForm.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | QApplication app(argc, argv); 8 | 9 | ApplicationFacade *af = new ApplicationFacade(); 10 | af->startUp(); 11 | 12 | Dialog *dlg = new Dialog(); 13 | dlg->show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /src/Patterns/Notifier.h: -------------------------------------------------------------------------------- 1 | #ifndef NOTIFIER_H 2 | #define NOTIFIER_H 3 | 4 | #include 5 | 6 | class IFacade; 7 | class INotification; 8 | 9 | class Notifier 10 | { 11 | public: 12 | Notifier(); 13 | 14 | void sendNotification(const QString ¬ificationName, void *body); 15 | 16 | protected: 17 | IFacade *m_facade; 18 | }; 19 | 20 | #endif // NOTIFIER_H 21 | -------------------------------------------------------------------------------- /src/Patterns/Command.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMAND_H 2 | #define COMMAND_H 3 | 4 | #include "../Interface/ICommand.h" 5 | #include "../Interface/IObserver.h" 6 | 7 | class Command : public ICommand, public IObserver 8 | { 9 | public: 10 | virtual void excute(INotification *notification); 11 | 12 | void notifyObserver(INotification *notification); 13 | }; 14 | 15 | #endif // COMMAND_H 16 | -------------------------------------------------------------------------------- /src/ApplicationFacade.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATIONFACADE_H 2 | #define APPLICATIONFACADE_H 3 | 4 | #include "Patterns/Facade.h" 5 | 6 | class ApplicationFacade : public Facade 7 | { 8 | public: 9 | ApplicationFacade(); 10 | 11 | protected: 12 | void initializeMediator(); 13 | void initializeCommand(); 14 | void initializeProxy(); 15 | }; 16 | 17 | #endif // APPLICATIONFACADE_H 18 | -------------------------------------------------------------------------------- /src/Interface/IUpdateData.h: -------------------------------------------------------------------------------- 1 | #ifndef IUPDATEDATA_H 2 | #define IUPDATEDATA_H 3 | 4 | #include 5 | 6 | class QString; 7 | 8 | class IUpdateData : public QObject 9 | { 10 | public: 11 | /*virtual QString getType() const = 0; 12 | 13 | virtual QString setType(const QString &type) = 0;*/ 14 | 15 | virtual QString getName() const = 0; 16 | }; 17 | 18 | #endif // IUPDATEDATA_H 19 | -------------------------------------------------------------------------------- /src/Patterns/Notification.cpp: -------------------------------------------------------------------------------- 1 | #include "Notification.h" 2 | 3 | Notification::Notification(const QString ¬ificationName, void *body) 4 | { 5 | m_notificationName = notificationName; 6 | m_body = body; 7 | } 8 | 9 | QString Notification::getNotificationName() 10 | { 11 | return m_notificationName; 12 | } 13 | 14 | void *Notification::getBody() 15 | { 16 | return m_body; 17 | } 18 | -------------------------------------------------------------------------------- /src/Interface/ICommand.h: -------------------------------------------------------------------------------- 1 | #ifndef ICOMMAND_H 2 | #define ICOMMAND_H 3 | 4 | class INotification; 5 | 6 | class ICommand 7 | { 8 | public: 9 | /** 10 | * Execute the ICommand's logic to handle a given INotification. 11 | * @param notification An INotification to handle. 12 | */ 13 | virtual void excute(INotification *notification) = 0; 14 | }; 15 | 16 | #endif // ICOMMAND_H 17 | -------------------------------------------------------------------------------- /src/Patterns/UpdateData.h: -------------------------------------------------------------------------------- 1 | #ifndef UPDATEDATA_H 2 | #define UPDATEDATA_H 3 | 4 | #include "../Interface/IUpdateData.h" 5 | 6 | class UpdateData : public IUpdateData 7 | { 8 | public: 9 | /*QString getType() const; 10 | 11 | QString setType(const QString &type);*/ 12 | 13 | QString getName() const; 14 | 15 | protected: 16 | //QString m_updateDataType; 17 | QString m_updateDataName; 18 | }; 19 | 20 | #endif // UPDATEDATA_H 21 | -------------------------------------------------------------------------------- /src/LoginCommand.cpp: -------------------------------------------------------------------------------- 1 | #include "LoginCommand.h" 2 | #include "Patterns/Facade.h" 3 | #include "LoginProxy.h" 4 | #include "LoginResult.h" 5 | #include "Interface/INotification.h" 6 | 7 | LoginCommand::LoginCommand() 8 | { 9 | } 10 | 11 | void LoginCommand::excute(INotification *notification) 12 | { 13 | LoginProxy *loginProxy = (LoginProxy *)Facade::getInstance()->retrieveProxy("LoginProxy"); 14 | 15 | loginProxy->checkLogin((LoginInfo *)notification->getBody()); 16 | } 17 | -------------------------------------------------------------------------------- /src/Patterns/Notification.h: -------------------------------------------------------------------------------- 1 | #ifndef NOTIFICATION_H 2 | #define NOTIFICATION_H 3 | 4 | #include "../Interface/INotification.h" 5 | 6 | #include 7 | 8 | class Notification : public INotification 9 | { 10 | public: 11 | Notification(const QString ¬ificationName, void *body); 12 | 13 | QString getNotificationName(); 14 | 15 | void *getBody(); 16 | 17 | protected: 18 | QString m_notificationName; 19 | void *m_body; 20 | }; 21 | 22 | #endif // NOTIFICATION_H 23 | -------------------------------------------------------------------------------- /src/Patterns/Proxy.h: -------------------------------------------------------------------------------- 1 | #ifndef PROXY_H 2 | #define PROXY_H 3 | 4 | #include "../Interface/IProxy.h" 5 | #include "Notifier.h" 6 | 7 | #include 8 | 9 | class IUpdateData; 10 | 11 | class Proxy : public IProxy, public Notifier 12 | { 13 | public: 14 | QString getProxyName(); 15 | 16 | /*protected: 17 | bool registerUpdateData(const QString ®isterDataType, IUpdateData *updateData);*/ 18 | 19 | protected: 20 | static QString PROXY_NAME; 21 | }; 22 | 23 | #endif // PROXY_H 24 | -------------------------------------------------------------------------------- /src/Interface/IMediator.h: -------------------------------------------------------------------------------- 1 | #ifndef IMEDIATOR_H 2 | #define IMEDIATOR_H 3 | 4 | class INotification; 5 | class IViewComponent; 6 | class QString; 7 | 8 | #include 9 | 10 | class IMediator 11 | { 12 | public: 13 | virtual void registerViewComponent(IViewComponent *viewComponent) = 0; 14 | 15 | virtual QString getMediatorName() = 0; 16 | 17 | virtual QList getListNotificationInterests() = 0; 18 | 19 | virtual void handleNotification(INotification *notification) = 0; 20 | }; 21 | 22 | #endif // IMEDIATOR_H 23 | -------------------------------------------------------------------------------- /src/LoginMediator.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINMEDIATOR_H 2 | #define LOGINMEDIATOR_H 3 | 4 | #include "Patterns/Mediator.h" 5 | 6 | class LoginInfo; 7 | 8 | class LoginMediator : public Mediator 9 | { 10 | public: 11 | LoginMediator(); 12 | 13 | QList getListNotificationInterests(); 14 | 15 | void handleNotification(INotification *notification); 16 | 17 | // special 18 | void doLogin(LoginInfo *loginInfo); 19 | 20 | private: 21 | QList m_notificationInterests; 22 | }; 23 | 24 | #endif // LOGINMEDIATOR_H 25 | -------------------------------------------------------------------------------- /src/ApplicationFacade.cpp: -------------------------------------------------------------------------------- 1 | #include "ApplicationFacade.h" 2 | #include "LoginCommand.h" 3 | #include "LoginMediator.h" 4 | #include "LoginProxy.h" 5 | 6 | ApplicationFacade::ApplicationFacade() : Facade() 7 | { 8 | } 9 | 10 | void ApplicationFacade::initializeMediator() 11 | { 12 | registerMediator(new LoginMediator()); 13 | } 14 | 15 | void ApplicationFacade::initializeCommand() 16 | { 17 | registerCommand("login_check", new LoginCommand()); 18 | } 19 | 20 | void ApplicationFacade::initializeProxy() 21 | { 22 | registerProxy(new LoginProxy()); 23 | } 24 | -------------------------------------------------------------------------------- /src/Interface/INotification.h: -------------------------------------------------------------------------------- 1 | #ifndef INOTIFICATION_H 2 | #define INOTIFICATION_H 3 | 4 | class QString; 5 | 6 | class INotification 7 | { 8 | public: 9 | /** 10 | * Get the name of the INotification instance. 11 | * @return The name of the INotification instance 12 | */ 13 | virtual QString getNotificationName() = 0; 14 | 15 | /** 16 | * Get the body of the INotification instance. 17 | * @return The body of the INotification instance 18 | */ 19 | virtual void *getBody() = 0; 20 | }; 21 | 22 | #endif // INOTIFICATION_H 23 | -------------------------------------------------------------------------------- /src/Patterns/Mediator.cpp: -------------------------------------------------------------------------------- 1 | #include "Mediator.h" 2 | #include "../Interface/INotification.h" 3 | 4 | QString Mediator::MEDIATOR_NAME = "Mediator"; 5 | 6 | void Mediator::registerViewComponent(IViewComponent *viewComponent) 7 | { 8 | if (viewComponent == NULL) 9 | { 10 | return; 11 | } 12 | 13 | m_viewComponent = viewComponent; 14 | } 15 | 16 | QString Mediator::getMediatorName() 17 | { 18 | return MEDIATOR_NAME; 19 | } 20 | 21 | void Mediator::notifyObserver(INotification *notification) 22 | { 23 | handleNotification(notification); 24 | } 25 | -------------------------------------------------------------------------------- /src/Core/Model.h: -------------------------------------------------------------------------------- 1 | #ifndef MODEL_H 2 | #define MODEL_H 3 | 4 | #include "../Interface/IModel.h" 5 | 6 | #include 7 | #include 8 | 9 | class Model : public IModel 10 | { 11 | public: 12 | static Model *getInstance(); 13 | 14 | void registerProxy(IProxy *proxy); 15 | 16 | IProxy *retrieveProxy(const QString &proxyName); 17 | 18 | bool hasProxy(const QString &proxyName); 19 | 20 | void removeProxy(const QString &proxyName); 21 | 22 | private: 23 | Model(); 24 | 25 | private: 26 | QMap m_proxyMap; 27 | static Model *m_instance; 28 | }; 29 | 30 | #endif // MODEL_H 31 | -------------------------------------------------------------------------------- /src/LoginForm.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINFORM_H 2 | #define LOGINFORM_H 3 | 4 | #include 5 | 6 | #include "Interface/IViewComponent.h" 7 | 8 | namespace Ui { 9 | class Dialog; 10 | } 11 | 12 | class LoginMediator; 13 | 14 | class Dialog : public QDialog, public IViewComponent { 15 | Q_OBJECT 16 | public: 17 | Dialog(QWidget *parent = 0); 18 | ~Dialog(); 19 | void update(IUpdateData *updateData); 20 | 21 | protected: 22 | void changeEvent(QEvent *e); 23 | 24 | private: 25 | Ui::Dialog *ui; 26 | LoginMediator *loginMediator; 27 | 28 | private slots: 29 | void on_loginButton_clicked(); 30 | }; 31 | 32 | #endif // LOGINFORM_H 33 | -------------------------------------------------------------------------------- /src/LoginProxy.cpp: -------------------------------------------------------------------------------- 1 | #include "LoginProxy.h" 2 | #include "LoginResult.h" 3 | #include "LoginInfo.h" 4 | 5 | LoginProxy::LoginProxy() 6 | { 7 | PROXY_NAME = "LoginProxy"; 8 | } 9 | 10 | void LoginProxy::checkLogin(LoginInfo *loginInfo) 11 | { 12 | LoginResult *loginResult = new LoginResult(); 13 | 14 | QString name = loginInfo->name; 15 | QString passwd = loginInfo->password; 16 | if ((name == "AndroiderNWeber") && (passwd == "123456")) 17 | { 18 | loginResult->result = true; 19 | } 20 | else 21 | { 22 | loginResult->result = false; 23 | } 24 | 25 | sendNotification("login_success", (void *)loginResult); 26 | } 27 | -------------------------------------------------------------------------------- /src/Interface/IView.h: -------------------------------------------------------------------------------- 1 | #ifndef IVIEW_H 2 | #define IVIEW_H 3 | 4 | class IMediator; 5 | class INotification; 6 | class IObserver; 7 | class QString; 8 | 9 | class IView 10 | { 11 | public: 12 | virtual void registerObserver(IObserver *observer, const QString ¬ificationName) = 0; 13 | 14 | virtual void removeObserver(const QString ¬ificationName) = 0; 15 | 16 | virtual void notifyObservers(INotification *notification) = 0; 17 | 18 | virtual void registerMediator(IMediator *mediator) = 0; 19 | 20 | virtual IMediator *retrieveMediator(const QString &mediatorName) = 0; 21 | 22 | virtual bool hasMediator(const QString &mediatorName) = 0; 23 | 24 | virtual void removeMediator(const QString &mediatorName) = 0; 25 | }; 26 | 27 | #endif // IVIEW_H 28 | -------------------------------------------------------------------------------- /src/Core/Controller.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTROLLER_H 2 | #define CONTROLLER_H 3 | 4 | #include "../Interface/IController.h" 5 | 6 | #include 7 | #include 8 | 9 | class IView; 10 | 11 | class Controller : public IController 12 | { 13 | public: 14 | static Controller *getInstance(); 15 | 16 | void registerCommand(const QString ¬ificationName, ICommand *command); 17 | 18 | void excuteCommand(INotification *notification); 19 | 20 | bool hasCommand(const QString ¬ificationName); 21 | 22 | void removeCommand(const QString ¬ificationName); 23 | 24 | private: 25 | Controller(); 26 | 27 | private: 28 | QMap m_commandMap; 29 | static Controller *m_instance; 30 | IView *m_view; 31 | }; 32 | 33 | #endif // CONTROLLER_H 34 | -------------------------------------------------------------------------------- /src/Patterns/Mediator.h: -------------------------------------------------------------------------------- 1 | #ifndef MEDIATOR_H 2 | #define MEDIATOR_H 3 | 4 | #include "../Interface/IMediator.h" 5 | #include "../Interface/IObserver.h" 6 | #include "../Interface/IViewComponent.h" 7 | #include "Notifier.h" 8 | 9 | #include 10 | 11 | class Mediator : public IMediator, public Notifier, public IObserver 12 | { 13 | public: 14 | void registerViewComponent(IViewComponent *viewComponent); 15 | 16 | QString getMediatorName(); 17 | 18 | virtual QList getListNotificationInterests() = 0; 19 | 20 | virtual void handleNotification(INotification *notification) = 0; 21 | 22 | void notifyObserver(INotification *notification); 23 | 24 | protected: 25 | static QString MEDIATOR_NAME; 26 | IViewComponent *m_viewComponent; 27 | }; 28 | 29 | #endif // MEDIATOR_H 30 | -------------------------------------------------------------------------------- /src/login_dialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 80 20 | 250 21 | 75 22 | 23 23 | 24 | 25 | 26 | Login 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/LoginMediator.cpp: -------------------------------------------------------------------------------- 1 | #include "LoginMediator.h" 2 | #include "Interface/INotification.h" 3 | #include "LoginInfo.h" 4 | #include "LoginResult.h" 5 | 6 | #include 7 | 8 | LoginMediator::LoginMediator() 9 | { 10 | MEDIATOR_NAME = "LoginMediator"; 11 | 12 | m_notificationInterests.append("login_success"); 13 | m_notificationInterests.append("login_error"); 14 | } 15 | 16 | QList LoginMediator::getListNotificationInterests() 17 | { 18 | return m_notificationInterests; 19 | } 20 | 21 | void LoginMediator::handleNotification(INotification *notification) 22 | { 23 | if (notification->getNotificationName() == "login_success") 24 | { 25 | m_viewComponent->update((IUpdateData *)notification->getBody()); 26 | } 27 | } 28 | 29 | void LoginMediator::doLogin(LoginInfo *loginInfo) 30 | { 31 | sendNotification("login_check", loginInfo); 32 | } 33 | -------------------------------------------------------------------------------- /src/Core/View.h: -------------------------------------------------------------------------------- 1 | #ifndef VIEW_H 2 | #define VIEW_H 3 | 4 | #include "../Interface/IView.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | class INotification; 11 | 12 | class View : public IView 13 | { 14 | public: 15 | static View *getInstance(); 16 | 17 | void registerObserver(IObserver *observer, const QString ¬ificationName); 18 | 19 | void removeObserver(const QString ¬ificationName); 20 | 21 | void notifyObservers(INotification *notification); 22 | 23 | void registerMediator(IMediator *mediator); 24 | 25 | IMediator *retrieveMediator(const QString &mediatorName); 26 | 27 | bool hasMediator(const QString &mediatorName); 28 | 29 | void removeMediator(const QString &mediatorName); 30 | 31 | private: 32 | View(); 33 | 34 | private: 35 | QMap m_mediatorMap; 36 | QMap > m_observerMap; 37 | static View *m_instance; 38 | }; 39 | 40 | #endif // VIEW_H 41 | -------------------------------------------------------------------------------- /src/Core/Model.cpp: -------------------------------------------------------------------------------- 1 | #include "Model.h" 2 | #include "../Interface/IProxy.h" 3 | #include 4 | 5 | Model *Model::m_instance; 6 | 7 | Model::Model() 8 | { 9 | 10 | } 11 | 12 | Model *Model::getInstance() 13 | { 14 | if (m_instance == NULL) 15 | { 16 | m_instance = new Model(); 17 | } 18 | 19 | return m_instance; 20 | } 21 | 22 | void Model::registerProxy(IProxy *proxy) 23 | { 24 | if (proxy == NULL) 25 | { 26 | return; 27 | } 28 | 29 | if (hasProxy(proxy->getProxyName())) 30 | { 31 | return; 32 | } 33 | 34 | m_proxyMap[proxy->getProxyName()] = proxy; 35 | } 36 | 37 | IProxy *Model::retrieveProxy(const QString &proxyName) 38 | { 39 | if (!hasProxy(proxyName)) 40 | { 41 | return NULL; 42 | } 43 | 44 | return m_proxyMap[proxyName]; 45 | } 46 | 47 | bool Model::hasProxy(const QString &proxyName) 48 | { 49 | return m_proxyMap.contains(proxyName); 50 | } 51 | 52 | void Model::removeProxy(const QString &proxyName) 53 | { 54 | m_proxyMap.remove(proxyName); 55 | } 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## PureMVC_QT 项目说明 2 | 3 | #### 项目描述 4 | 基于 QTCreator 的 PureMVC 框架代码(包含demo),移植于该框架的 C++ 版本 5 | 6 | #### 项目结构 7 | 文件和路径 | 功能 8 | -----------|----------- 9 | src\ | 源码文件 10 | 11 | #### 详细描述 12 | 1. 该框架基于经典的Model-View-Controller三层框架思想,由 13 | Model-View-Controller构成其核心,并以Facade模式加以封装,以单例门面的形式 14 | 对外提供核心服务,如Proxy操作,Command操作以及Mediator操作,他们均由Facade 15 | 单例统一进行调度。 16 | 17 | 2. 客户端初始化时须对Mediator,Command,Proxy进行注册,以表明各自感兴趣的 18 | 消息(观察者模式中的订阅)。用户输入数据到View Components后,由Mediator 19 | 通知观察者Command数据更新(观察者模式中的发布),Command调用Proxy完成真正 20 | 的业务逻辑操作,完成后通知感兴趣的观察者Mediator(观察者模式中的发布)将 21 | 数据更新到View Components,完成整个数据流动处理过程。 22 | 23 | 3. 该框架大量用到了设计模式,包括: 24 | 1. 观察者模式:观察者模式是整个框架所使用的核心模式,其发布-订阅的机制 25 | 奠定了整个框架解耦的基础。 26 | 2. 门面模式:对Model-View-Controller核心组件复杂的功能进行封装,以统一 27 | 的门面形式对外提供服务,简化了调用者的复杂度。 28 | 3. 中介者模式:隔离UI组件和其他框架组件,由中介者来统一完成UI组件与框 29 | 架组件的交互,使UI组件与框架松耦合。 30 | 4. 单例模式:对Model,View,Controller和Facade均只提供全局唯一的实例, 31 | 调用者只需调用统一接口即可。 32 | 5. 代理模式:Proxy对业务处理和数据访问提供了隔离控制,可以灵活地制定业 33 | 务逻辑之外的操作。 34 | 6. 命令模式:Command使用统一的execute命令和INotification通知来隔离命令 35 | 调用者和命令执行者。 36 | 37 | -------------------------------------------------------------------------------- /src/Interface/IModel.h: -------------------------------------------------------------------------------- 1 | #ifndef IMODEL_H 2 | #define IMODEL_H 3 | 4 | class IProxy; 5 | class QString; 6 | 7 | class IModel 8 | { 9 | public: 10 | /** 11 | * Register an IProxy instance with the Model. 12 | * @param proxy A reference to the proxy object to be held by the Model. 13 | */ 14 | virtual void registerProxy(IProxy *proxy) = 0; 15 | 16 | /** 17 | * Retrieve an IProxy instance from the Model. 18 | * @param proxyName The name of the proxy to retrieve. 19 | */ 20 | virtual IProxy *retrieveProxy(const QString &proxyName) = 0; 21 | 22 | /** 23 | * Check if a Proxy is registered. 24 | * @param proxyName The name of the proxy to check for. 25 | * @return Whether a Proxy is currently registered with the given proxyName. 26 | */ 27 | virtual bool hasProxy(const QString &proxyName) = 0; 28 | 29 | /** 30 | * Check if a Proxy is registered. 31 | * @param proxyName The name of the proxy to check for. 32 | * @return Whether a Proxy is currently registered with the given proxyName. 33 | */ 34 | virtual void removeProxy(const QString &proxyName) = 0; 35 | }; 36 | 37 | #endif // IMODEL_H 38 | -------------------------------------------------------------------------------- /src/Interface/IFacade.h: -------------------------------------------------------------------------------- 1 | #ifndef IFACADE_H 2 | #define IFACADE_H 3 | 4 | #include "INotifier.h" 5 | 6 | class ICommand; 7 | class IMediator; 8 | class INotification; 9 | class IObserver; 10 | class IProxy; 11 | class QString; 12 | 13 | class IFacade : public INotifier 14 | { 15 | public: 16 | virtual void registerObserver(IObserver *observer, const QString ¬ificationName) = 0; 17 | 18 | virtual void removeObserver(const QString ¬ificationName) = 0; 19 | 20 | virtual void notifyObservers(INotification *notification) = 0; 21 | 22 | virtual void registerMediator(IMediator *mediator) = 0; 23 | 24 | virtual IMediator *retrieveMediator(const QString &mediatorName) = 0; 25 | 26 | virtual bool hasMediator(const QString &mediatorName) = 0; 27 | 28 | virtual void removeMediator(const QString &mediatorName) = 0; 29 | 30 | 31 | virtual void registerCommand(const QString ¬ificationName, ICommand *command) = 0; 32 | 33 | virtual bool hasCommand(const QString ¬ificationName) = 0; 34 | 35 | virtual void removeCommand(const QString ¬ificationName) = 0; 36 | 37 | 38 | virtual void registerProxy(IProxy *proxy) = 0; 39 | 40 | virtual IProxy *retrieveProxy(const QString &proxyName) = 0; 41 | 42 | virtual bool hasProxy(const QString &proxyName) = 0; 43 | 44 | virtual void removeProxy(const QString &proxyName) = 0; 45 | }; 46 | 47 | #endif // IFACADE_H 48 | -------------------------------------------------------------------------------- /src/Core/Controller.cpp: -------------------------------------------------------------------------------- 1 | #include "Controller.h" 2 | #include "../Interface/ICommand.h" 3 | #include "../Interface/INotification.h" 4 | #include "view.h" 5 | 6 | Controller *Controller::m_instance; 7 | 8 | Controller::Controller() 9 | { 10 | m_view = View::getInstance(); 11 | } 12 | 13 | Controller *Controller::getInstance() 14 | { 15 | if (m_instance == NULL) 16 | { 17 | m_instance = new Controller(); 18 | } 19 | 20 | return m_instance; 21 | } 22 | 23 | void Controller::registerCommand(const QString ¬ificationName, ICommand *command) 24 | { 25 | if (command == NULL) 26 | { 27 | return; 28 | } 29 | 30 | if (hasCommand(notificationName)) 31 | { 32 | return; 33 | } 34 | 35 | m_commandMap[notificationName] = command; 36 | 37 | m_view->registerObserver((IObserver *)command, notificationName); 38 | } 39 | 40 | void Controller::excuteCommand(INotification *notification) 41 | { 42 | if (!hasCommand(notification->getNotificationName())) 43 | { 44 | return; 45 | } 46 | 47 | ICommand *command = m_commandMap[notification->getNotificationName()]; 48 | command->excute(notification); 49 | } 50 | 51 | bool Controller::hasCommand(const QString ¬ificationName) 52 | { 53 | return m_commandMap.contains(notificationName); 54 | } 55 | 56 | void Controller::removeCommand(const QString ¬ificationName) 57 | { 58 | m_commandMap.remove(notificationName); 59 | } 60 | -------------------------------------------------------------------------------- /src/LoginForm.cpp: -------------------------------------------------------------------------------- 1 | #include "LoginForm.h" 2 | #include "ui_login_dialog.h" 3 | #include "Patterns/Facade.h" 4 | #include "LoginMediator.h" 5 | #include "LoginInfo.h" 6 | #include "LoginResult.h" 7 | 8 | #include 9 | 10 | Dialog::Dialog(QWidget *parent) : 11 | QDialog(parent), 12 | ui(new Ui::Dialog) 13 | { 14 | ui->setupUi(this); 15 | 16 | Facade *facade = Facade::getInstance(); 17 | loginMediator = (LoginMediator *)facade->retrieveMediator("LoginMediator"); 18 | loginMediator->registerViewComponent(this); 19 | } 20 | 21 | Dialog::~Dialog() 22 | { 23 | delete ui; 24 | } 25 | 26 | void Dialog::update(IUpdateData *updateData) 27 | { 28 | if (updateData->getName() == "LoginResult") 29 | { 30 | LoginResult *loginResult = (LoginResult *)updateData; 31 | 32 | if (loginResult->result) 33 | { 34 | qDebug() << "Success"; 35 | } 36 | else 37 | { 38 | qDebug() << "Fail"; 39 | } 40 | } 41 | } 42 | 43 | void Dialog::changeEvent(QEvent *e) 44 | { 45 | QDialog::changeEvent(e); 46 | switch (e->type()) { 47 | case QEvent::LanguageChange: 48 | ui->retranslateUi(this); 49 | break; 50 | default: 51 | break; 52 | } 53 | } 54 | 55 | void Dialog::on_loginButton_clicked() 56 | { 57 | LoginInfo *loginInfo = new LoginInfo(); 58 | 59 | loginInfo->name = "AndroiderNWeber"; 60 | loginInfo->password = "123456"; 61 | 62 | loginMediator->doLogin(loginInfo); 63 | } 64 | -------------------------------------------------------------------------------- /src/Interface/IController.h: -------------------------------------------------------------------------------- 1 | #ifndef ICONTROLLER_H 2 | #define ICONTROLLER_H 3 | 4 | class ICommand; 5 | class INotification; 6 | class QString; 7 | 8 | class IController 9 | { 10 | public: 11 | /** 12 | * Register a particular ICommand class as the handler for a particular INotification. 13 | * @param notificationName The name of the INotification. 14 | * @param command The ICommand to handle the INotification. 15 | */ 16 | virtual void registerCommand(const QString ¬ificationName, ICommand *command) = 0; 17 | 18 | /** 19 | * Execute the ICommand previously registered as the handler for INotifications with the given notification name. 20 | * @param notification The INotification to execute the associated ICommand for. 21 | */ 22 | virtual void excuteCommand(INotification *notification) = 0; 23 | 24 | /** 25 | * Check if a Command is registered for a given Notification. 26 | * @param notificationName The name of the INotification. 27 | * return Whether a Command is currently registered for the given notificationName 28 | */ 29 | virtual bool hasCommand(const QString ¬ificationName) = 0; 30 | 31 | /** 32 | * Remove a previously registered ICommand to INotification mapping. 33 | * @param notificationName The name of the INotification. 34 | * return Whether a Command is currently registered for the given notificationName 35 | */ 36 | virtual void removeCommand(const QString ¬ificationName) = 0; 37 | }; 38 | 39 | #endif // ICONTROLLER_H 40 | -------------------------------------------------------------------------------- /src/ui_login_dialog.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | ** Form generated from reading UI file 'login_dialog.ui' 3 | ** 4 | ** Created: Sat Oct 6 10:01:08 2012 5 | ** by: Qt User Interface Compiler version 4.6.3 6 | ** 7 | ** WARNING! All changes made in this file will be lost when recompiling UI file! 8 | ********************************************************************************/ 9 | 10 | #ifndef UI_LOGIN_DIALOG_H 11 | #define UI_LOGIN_DIALOG_H 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | QT_BEGIN_NAMESPACE 22 | 23 | class Ui_Dialog 24 | { 25 | public: 26 | QPushButton *loginButton; 27 | 28 | void setupUi(QDialog *Dialog) 29 | { 30 | if (Dialog->objectName().isEmpty()) 31 | Dialog->setObjectName(QString::fromUtf8("Dialog")); 32 | Dialog->resize(400, 300); 33 | loginButton = new QPushButton(Dialog); 34 | loginButton->setObjectName(QString::fromUtf8("loginButton")); 35 | loginButton->setGeometry(QRect(80, 250, 75, 23)); 36 | 37 | retranslateUi(Dialog); 38 | 39 | QMetaObject::connectSlotsByName(Dialog); 40 | } // setupUi 41 | 42 | void retranslateUi(QDialog *Dialog) 43 | { 44 | Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8)); 45 | loginButton->setText(QApplication::translate("Dialog", "Login", 0, QApplication::UnicodeUTF8)); 46 | } // retranslateUi 47 | 48 | }; 49 | 50 | namespace Ui { 51 | class Dialog: public Ui_Dialog {}; 52 | } // namespace Ui 53 | 54 | QT_END_NAMESPACE 55 | 56 | #endif // UI_LOGIN_DIALOG_H 57 | -------------------------------------------------------------------------------- /src/Patterns/Facade.h: -------------------------------------------------------------------------------- 1 | #ifndef FACADE_H 2 | #define FACADE_H 3 | 4 | #include 5 | #include "../Interface/IFacade.h" 6 | #include "../Interface/ICommand.h" 7 | #include "../Interface/IMediator.h" 8 | #include "../Interface/IObserver.h" 9 | #include "../Interface/IProxy.h" 10 | 11 | class IModel; 12 | class IView; 13 | class IController; 14 | 15 | class Facade : public IFacade 16 | { 17 | public: 18 | static Facade *getInstance(); 19 | 20 | void registerObserver(IObserver *observer, const QString ¬ificationName); 21 | 22 | void removeObserver(const QString ¬ificationName); 23 | 24 | void notifyObservers(INotification *notification); 25 | 26 | void registerMediator(IMediator *mediator); 27 | 28 | IMediator *retrieveMediator(const QString &mediatorName); 29 | 30 | bool hasMediator(const QString &mediatorName); 31 | 32 | void removeMediator(const QString &mediatorName); 33 | 34 | 35 | 36 | void registerCommand(const QString ¬ificationName, ICommand *command); 37 | 38 | bool hasCommand(const QString ¬ificationName); 39 | 40 | void removeCommand(const QString ¬ificationName); 41 | 42 | 43 | void registerProxy(IProxy *proxy); 44 | 45 | IProxy *retrieveProxy(const QString &proxyName); 46 | 47 | bool hasProxy(const QString &proxyName); 48 | 49 | void removeProxy(const QString &proxyName); 50 | 51 | 52 | void sendNotification(const QString ¬ificationName, void *body); 53 | 54 | void startUp(); 55 | 56 | protected: 57 | virtual void initializeMediator(); 58 | virtual void initializeCommand(); 59 | virtual void initializeProxy(); 60 | 61 | protected: 62 | Facade(); 63 | 64 | private: 65 | IView *m_view; 66 | IController *m_controller; 67 | IModel *m_model; 68 | static Facade *m_instance; 69 | }; 70 | 71 | #endif // FACADE_H 72 | -------------------------------------------------------------------------------- /src/Core/View.cpp: -------------------------------------------------------------------------------- 1 | #include "View.h" 2 | #include "../Interface/IMediator.h" 3 | #include "../Interface/INotification.h" 4 | #include "../Interface/IObserver.h" 5 | #include "../Patterns/Mediator.h" 6 | 7 | View *View::m_instance; 8 | 9 | View::View() 10 | { 11 | 12 | } 13 | 14 | View *View::getInstance() 15 | { 16 | if (m_instance == NULL) 17 | { 18 | m_instance = new View(); 19 | } 20 | 21 | return m_instance; 22 | } 23 | 24 | void View::registerObserver(IObserver *observer, const QString ¬ificationName) 25 | { 26 | if (observer == NULL) 27 | { 28 | return; 29 | } 30 | 31 | if (m_observerMap.contains(notificationName)) 32 | { 33 | QList observers = m_observerMap[notificationName]; 34 | if (observers.contains(observer)) 35 | { 36 | return; 37 | } 38 | 39 | observers.append(observer); 40 | 41 | m_observerMap[notificationName] = observers; 42 | } 43 | else 44 | { 45 | QList observers; 46 | 47 | observers.append(observer); 48 | 49 | m_observerMap[notificationName] = observers; 50 | } 51 | } 52 | 53 | void View::removeObserver(const QString ¬ificationName) 54 | { 55 | if (!m_observerMap.contains(notificationName)) 56 | { 57 | return; 58 | } 59 | 60 | m_observerMap.remove(notificationName); 61 | } 62 | 63 | void View::notifyObservers(INotification *notification) 64 | { 65 | if (!m_observerMap.contains(notification->getNotificationName())) 66 | { 67 | return; 68 | } 69 | 70 | QList observers = m_observerMap[notification->getNotificationName()]; 71 | 72 | int count = observers.size(); 73 | for (int i = 0; i < count; i++) 74 | { 75 | observers.at(i)->notifyObserver(notification); 76 | } 77 | } 78 | 79 | void View::registerMediator(IMediator *mediator) 80 | { 81 | if (mediator == NULL) 82 | { 83 | return; 84 | } 85 | 86 | m_mediatorMap[mediator->getMediatorName()] = mediator; 87 | 88 | QList notificationInterests = mediator->getListNotificationInterests(); 89 | 90 | int count = notificationInterests.size(); 91 | for (int i = 0; i < count; i++) 92 | { 93 | registerObserver((IObserver *)((Mediator *)mediator), notificationInterests.at(i)); 94 | } 95 | } 96 | 97 | IMediator *View::retrieveMediator(const QString &mediatorName) 98 | { 99 | if (!hasMediator(mediatorName)) 100 | { 101 | return NULL; 102 | } 103 | 104 | return m_mediatorMap[mediatorName]; 105 | } 106 | 107 | bool View::hasMediator(const QString &mediatorName) 108 | { 109 | return m_mediatorMap.contains(mediatorName); 110 | } 111 | 112 | void View::removeMediator(const QString &mediatorName) 113 | { 114 | m_mediatorMap.remove(mediatorName); 115 | } 116 | -------------------------------------------------------------------------------- /src/Patterns/Facade.cpp: -------------------------------------------------------------------------------- 1 | #include "Facade.h" 2 | #include "../Interface/IModel.h" 3 | #include "../Interface/IController.h" 4 | #include "../Interface/IView.h" 5 | #include "../Core/Model.h" 6 | #include "../Core/Controller.h" 7 | #include "../Core/View.h" 8 | #include "Notification.h" 9 | 10 | Facade *Facade::m_instance; 11 | 12 | Facade::Facade() 13 | { 14 | m_view = View::getInstance(); 15 | m_model = Model::getInstance(); 16 | m_controller = Controller::getInstance(); 17 | 18 | initializeMediator(); 19 | initializeCommand(); 20 | initializeProxy(); 21 | } 22 | 23 | Facade *Facade::getInstance() 24 | { 25 | if (m_instance == NULL) 26 | { 27 | m_instance = new Facade(); 28 | } 29 | 30 | return m_instance; 31 | } 32 | 33 | void Facade::initializeMediator() 34 | { 35 | 36 | } 37 | 38 | void Facade::initializeCommand() 39 | { 40 | 41 | } 42 | 43 | void Facade::initializeProxy() 44 | { 45 | 46 | } 47 | 48 | 49 | void Facade::registerObserver(IObserver *observer, const QString ¬ificationName) 50 | { 51 | m_view->registerObserver(observer, notificationName); 52 | } 53 | 54 | void Facade::removeObserver(const QString ¬ificationName) 55 | { 56 | m_view->removeObserver(notificationName); 57 | } 58 | 59 | void Facade::notifyObservers(INotification *notification) 60 | { 61 | m_view->notifyObservers(notification); 62 | } 63 | 64 | 65 | void Facade::registerMediator(IMediator *mediator) 66 | { 67 | m_view->registerMediator(mediator); 68 | } 69 | 70 | IMediator *Facade::retrieveMediator(const QString &mediatorName) 71 | { 72 | return m_view->retrieveMediator(mediatorName); 73 | } 74 | 75 | bool Facade::hasMediator(const QString &mediatorName) 76 | { 77 | return m_view->hasMediator(mediatorName); 78 | } 79 | 80 | void Facade::removeMediator(const QString &mediatorName) 81 | { 82 | m_view->removeMediator(mediatorName); 83 | } 84 | 85 | 86 | 87 | void Facade::registerCommand(const QString ¬ificationName, ICommand *command) 88 | { 89 | m_controller->registerCommand(notificationName, command); 90 | } 91 | 92 | bool Facade::hasCommand(const QString ¬ificationName) 93 | { 94 | return m_controller->hasCommand(notificationName); 95 | } 96 | 97 | void Facade::removeCommand(const QString ¬ificationName) 98 | { 99 | m_controller->removeCommand(notificationName); 100 | } 101 | 102 | 103 | void Facade::registerProxy(IProxy *proxy) 104 | { 105 | m_model->registerProxy(proxy); 106 | } 107 | 108 | IProxy *Facade::retrieveProxy(const QString &proxyName) 109 | { 110 | return m_model->retrieveProxy(proxyName); 111 | } 112 | 113 | bool Facade::hasProxy(const QString &proxyName) 114 | { 115 | return m_model->hasProxy(proxyName); 116 | } 117 | 118 | void Facade::removeProxy(const QString &proxyName) 119 | { 120 | m_model->removeProxy(proxyName); 121 | } 122 | 123 | void Facade::sendNotification(const QString ¬ificationName, void *body) 124 | { 125 | m_view->notifyObservers(new Notification(notificationName, body)); 126 | } 127 | 128 | void Facade::startUp() 129 | { 130 | initializeCommand(); 131 | initializeProxy(); 132 | initializeMediator(); 133 | } 134 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------