-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <memory> | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\JobApplication.h" | ||
using namespace std; | ||
|
||
#ifndef BASE_HANDLER_H | ||
#define BASE_HANDLER_H | ||
|
||
class BaseHandler { | ||
protected: | ||
shared_ptr<BaseHandler> nextHandler; | ||
|
||
public: | ||
void setNext(shared_ptr<BaseHandler> handler) { | ||
nextHandler = handler; | ||
} | ||
|
||
virtual void HandleRequest(shared_ptr<JobApplication> request) = 0; | ||
|
||
virtual ~BaseHandler() = default; | ||
}; | ||
|
||
#endif // BASE_HANDLER_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
#include <memory> | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\BaseHandler.h" | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\HRHandler.h" | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\JobApplication.h" | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\TechHandler.h" | ||
using namespace std; | ||
|
||
int main() { | ||
shared_ptr<JobApplication> jobApp = make_shared<JobApplication>(); | ||
jobApp -> ApplicantName = "Hend"; | ||
jobApp -> JobTitle = "SDE"; | ||
jobApp -> JobCode = "#122524"; | ||
|
||
shared_ptr<HRHandler> hr = make_shared<HRHandler>(); | ||
shared_ptr<TechHandler> tech = make_shared<TechHandler>(); | ||
|
||
hr -> setNext(tech); // create the chain | ||
|
||
hr -> HandleRequest(jobApp); // start the chain | ||
|
||
|
||
cout << jobApp -> showComments(); | ||
|
||
} |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\BaseHandler.h" | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\JobApplication.h" | ||
#include <memory> | ||
|
||
#ifndef HR_HANDLER_H | ||
#define HR_HANDLER_H | ||
|
||
class HRHandler : public BaseHandler { | ||
public: | ||
void toNext_Scenario3(shared_ptr <JobApplication> request) { | ||
if(nextHandler != nullptr) { | ||
nextHandler -> HandleRequest(request); | ||
} | ||
else { | ||
request -> comments << "End by HR...\n"; | ||
} | ||
} | ||
|
||
void HandleRequest(shared_ptr<JobApplication> request) override{ | ||
|
||
#pragma region Scenario 1 | ||
// request -> comments << "HR evaluation comment.\n"; | ||
|
||
// if(nextHandler != nullptr) { | ||
// nextHandler -> HandleRequest(request); | ||
// } | ||
// else { | ||
// request -> comments << "End by HR Handler\n"; | ||
// } | ||
#pragma endregion | ||
|
||
#pragma region Scenario 2 | ||
// check if the handler is able to process the request or not | ||
// if (request -> JobCode == "#1546") { | ||
// request -> comments << "HR Comment...\n"; | ||
// } | ||
// else{ // send request to the next handler | ||
// if (nextHandler != nullptr) { | ||
// nextHandler -> HandleRequest(request); | ||
// } | ||
// else { | ||
// request -> comments << "End by HR Handler...\n"; | ||
// } | ||
// } | ||
#pragma endregion | ||
|
||
if (request -> JobCode == "#1546") { | ||
request -> comments << "HR Comment...\n"; | ||
toNext_Scenario3(request); | ||
} | ||
else { | ||
toNext_Scenario3(request); | ||
} | ||
} | ||
|
||
}; | ||
|
||
#endif // HR_HANDLER_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <string> | ||
#include <sstream> | ||
using namespace std; | ||
|
||
#ifndef JOB_APPLICATION_H | ||
#define JOB_APPLICATION_H | ||
|
||
class JobApplication { | ||
public: | ||
string ApplicantName; | ||
string JobTitle; | ||
string JobCode; | ||
stringstream comments; | ||
|
||
string getComments() const { | ||
return comments.str(); | ||
} | ||
|
||
void setComments(const string& newComments) { | ||
comments.str(""); | ||
comments << newComments; | ||
} | ||
|
||
string showComments() const { | ||
return comments.str(); | ||
} | ||
}; | ||
|
||
#endif // JOB_APPLICATION_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\BaseHandler.h" | ||
#include "C:\Users\Data-DCS\Design-Patterns\Behavioral\ChainOfResponsibility\JobApplication.h" | ||
#include <sstream> | ||
|
||
|
||
#ifndef TECH_HANDLER_H | ||
#define TECH_HANDLER_H | ||
|
||
class TechHandler : public BaseHandler { | ||
public: | ||
void toNext_Scenario3(shared_ptr <JobApplication> request) { | ||
if (nextHandler != nullptr) { | ||
nextHandler -> HandleRequest(request); | ||
} | ||
else { | ||
request -> comments << "End by tech...\n"; | ||
} | ||
} | ||
|
||
void HandleRequest(shared_ptr<JobApplication> request) override{ | ||
|
||
#pragma region Scenario 1 | ||
// request -> comments << "Tech evaluation comment.\n"; | ||
|
||
// if(nextHandler != nullptr) { | ||
// nextHandler -> HandleRequest(request); | ||
// } | ||
// else{ | ||
// request -> comments << "End by technical handler\n"; | ||
// } | ||
#pragma endregion | ||
|
||
#pragma region Scenario 2 | ||
// if (request -> JobCode == "#122524") { | ||
// request -> comments << "Tech Comment...\n"; | ||
// } | ||
// else{ | ||
// if(nextHandler != nullptr) { | ||
// nextHandler -> HandleRequest(request); | ||
// } | ||
// else { | ||
// request -> comments << "End by tech handler...\n"; | ||
// } | ||
// } | ||
#pragma endregion | ||
|
||
if(request -> JobCode == "#122524") { | ||
request -> comments << "Tech comment...\n"; | ||
toNext_Scenario3(request); | ||
} | ||
else { | ||
toNext_Scenario3(request); | ||
} | ||
} | ||
}; | ||
|
||
#endif // TECH_HANDLER_H |
File renamed without changes.
File renamed without changes.