Challenge: Solution Review
Explore how the chain of responsibility behavioral pattern assigns tasks based on employee skill levels. Learn to implement handler classes, set up a chain, and forward requests in JavaScript to manage work delegation efficiently.
We'll cover the following...
We'll cover the following...
Solution #
Explanation
In this challenge, you had to use the chain of responsibility pattern to assign work to employees. We start by creating an employee. Here’s what the Employee class looks like:
class Employee
{
constructor(name,level){
this.name = name
this.level = level
}
getLevel(){
return this.level
}
getName(){
return this.name
}
}
An employee will have a name and a level. Every employee can have one of the three levels: easy, medium, or hard. The level of an employee denotes the level of tasks that they can handle. So, an employee with an easy level can only handle easy tasks and the same goes for employees with medium and hard levels.
The getLevel and ...