Posts

Showing posts with the label GoF

Southwind : Gof Patterns example of Template method and Strategy patterns

Southwind C++ (codeblocks ide) project for GoF patterns practicing. It takes as example a possible template method from the trader company "Southwind" and the use of 2 different Strategies (Kanban and JustInTime). Files in project: main.cpp : #include #include "templatemethod.h" #include using namespace std; int main() { const static vector * catalog = {"Tablets offer", "SmartPhones offer", "Javas offer", "Androids offer", "Creatives offer"}; const static vector * locations = {"KanbanCity","JustInTimeCity"}; int status = -1; map > * tradingdata; Strategy * strategy = NULL; Context* context = NULL; TraderCompany* southwind = NULL; vector * preorder = createPreOrder(catalog); string* location = getLocation(locations); if(location->compare(locations->at(0))== 0)) /* we work with Kanban city */ strategy = new KanbanStrategy(); else strategy = new Justi...

GoF patterns launcher and Chain of Resposibility pattern example (C++)

A C++ (codeblocks ide) project for GoF patterns practicing.It can be extended with the rest of patterns (command, state, factory, mediator, etc...). Files in project: main.cpp : #include #include #include "chainofresp.h" #include "patternexec.h" using namespace std; const int CHAIN = 2; int main() { int sdirective = 2; PatternExec* _patterne = 0; string name ="CHAIN"; string conf = "1000"; switch(sdirective){ case CHAIN: _patterne = new PatternExec(new ChainOfResp(name,conf)); break; default: return -100; } int r = _patterne->execute(); if(!r) cout return r; } patternexec.h : It contains pattern's launcher (command) and specific pattern (in this case ChainOfResp) runner. #ifndef PATTERNEXEC_H_INCLUDED #define PATTERNEXEC_H_INCLUDED #include #include #include using namespace std; class Pattern { public: Pattern(); Pattern(string name, string conf); virtual int run();...