-
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.
organization structure - Composite Pattern
- Loading branch information
1 parent
2a96038
commit 5bc1e7d
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...g_2.0/Problems/Structural-pattern-problems/organization-structure-management.md
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,52 @@ | ||
# Composite Pattern: Advanced Organization Structure Management System | ||
|
||
## Overview | ||
|
||
This project implements an **Advanced Organization Structure Management System** using the **Composite Pattern**, allowing for a flexible and hierarchical representation of employees, teams, and departments. The system supports role-based access control, task management, and detailed reporting functionalities, making it suitable for complex organizational needs. | ||
|
||
## Features | ||
|
||
- **Hierarchical Structure**: Create a tree structure where employees can belong to teams or departments, enabling complex organizational hierarchies. | ||
- **Role-Based Access Control**: Assign different roles (e.g., Manager, Employee, Admin) to users to control access to certain functionalities within the system. | ||
- **Task Assignment**: Allow managers to assign tasks to employees or teams, track progress, and manage deadlines. | ||
- **Detailed Reporting**: Generate reports on employee performance, departmental achievements, and overall organizational statistics. | ||
- **Uniform Interface**: Provide a common interface for both individual employees and groups, allowing for consistent operations such as getting total salary, displaying employee details, or calculating task completion rates. | ||
|
||
## Internal Structure | ||
|
||
The project consists of the following components: | ||
|
||
1. **Component Interface** | ||
|
||
- Defines the common methods for both `Employee` and `Department`, ensuring that both can be treated uniformly. | ||
|
||
2. **Leaf Class (Employee)** | ||
|
||
- Represents individual employees in the organization. Implements methods for salary calculation, displaying details, and task management (e.g., adding, updating tasks). | ||
|
||
3. **Composite Class (Department)** | ||
|
||
- Represents a group of employees and/or other departments. Implements methods to manage its child components (employees or sub-departments) and handles task assignment at the departmental level. | ||
|
||
4. **Role Class** | ||
|
||
- Defines the different roles within the organization, including permissions associated with each role. | ||
|
||
5. **Reporting Class** | ||
|
||
- Responsible for generating reports based on organizational data, employee performance metrics, and task completion statistics. | ||
|
||
6. **Client Code** | ||
- Demonstrates how to create the organization structure, adding employees and departments, assigning tasks, and generating reports. | ||
|
||
## How to Use | ||
|
||
1. **Create Employees**: Instantiate `Employee` objects with necessary details (name, position, salary, role). | ||
2. **Create Departments**: Instantiate `Department` objects, which can contain employees or other departments. | ||
3. **Add Employees to Departments**: Use methods to add employees to departments or to add sub-departments. | ||
4. **Assign Tasks**: Managers can assign tasks to employees or teams, track their status, and set deadlines. | ||
5. **Generate Reports**: Call reporting methods to generate insights into employee performance, departmental achievements, and overall statistics. | ||
|
||
## Solution | ||
|
||
You can find the solution to this problem in the [solution folder](/Learning_2.0/Solutions/Structural-pattern-solutions/organization-structure-management/). |
23 changes: 23 additions & 0 deletions
23
...ning_2.0/Solutions/Structural-pattern-solutions/organization-structure-management/main.js
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,23 @@ | ||
// main.js | ||
const {Employee, Department} = require("./organizationStructure"); | ||
const Reporting = require("./reporting"); | ||
|
||
// Create Employees | ||
const emp1 = new Employee("Alice", "Developer", 60000, "Employee"); | ||
const emp2 = new Employee("Bob", "Manager", 80000, "Manager"); | ||
|
||
// Create Department | ||
const devDepartment = new Department("Development"); | ||
|
||
// Add Employees to Department | ||
devDepartment.add(emp1); | ||
devDepartment.add(emp2); | ||
|
||
// Assign Tasks | ||
emp1.assignTask("Complete project A"); | ||
emp2.assignTask("Manage team meetings"); | ||
|
||
// Generate Reports | ||
Reporting.generateReport(devDepartment); | ||
Reporting.generateEmployeeReport(emp1); | ||
Reporting.generateEmployeeReport(emp2); |
18 changes: 18 additions & 0 deletions
18
.../Solutions/Structural-pattern-solutions/organization-structure-management/organization.js
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,18 @@ | ||
class Organization { | ||
getDetails() { | ||
throw new Error("Method getDetails() must be implemented"); | ||
} | ||
add(component) { | ||
throw new Error("Method add() must be implemented"); | ||
} | ||
|
||
remove(component) { | ||
throw new Error("Method remove() must be implemented"); | ||
} | ||
|
||
assignTask(task) { | ||
throw new Error("Method assignTask() must be implemented"); | ||
} | ||
} | ||
|
||
module.exports = Organization; |
63 changes: 63 additions & 0 deletions
63
...s/Structural-pattern-solutions/organization-structure-management/organizationStructure.js
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,63 @@ | ||
// organizationStructure.js | ||
const Organization = require("./organization"); | ||
|
||
class Employee extends Organization { | ||
constructor(name, position, salary, role) { | ||
super(); | ||
this.name = name; | ||
this.position = position; | ||
this.salary = salary; | ||
this.role = role; | ||
this.tasks = []; | ||
} | ||
|
||
getDetails() { | ||
return `\n Name: ${this.name}, \n -Position: ${this.position}, \n -Salary: ${this.salary}, \n - Role: ${this.role}`; | ||
} | ||
|
||
assignTask(task) { | ||
this.tasks.push(task); | ||
} | ||
|
||
showTasks() { | ||
return this.tasks; | ||
} | ||
|
||
showSalary() { | ||
return this.salary; | ||
} | ||
} | ||
|
||
class Department extends Organization { | ||
constructor(name) { | ||
super(); | ||
this.name = name; | ||
this.employees = []; | ||
} | ||
|
||
getDetails() { | ||
const details = `Department: ${this.name} \n Employees:`; | ||
return details + this.employees.map((emp) => emp.getDetails()).join(""); | ||
} | ||
|
||
add(component) { | ||
if (component instanceof Organization) { | ||
this.employees.push(component); | ||
} | ||
} | ||
|
||
remove(component) { | ||
this.employees = this.employees.filter((emp) => emp !== component); | ||
} | ||
|
||
assignTask(task) { | ||
this.employees.forEach((emp) => { | ||
emp.assignTask(task); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { | ||
Employee, | ||
Department, | ||
}; |
13 changes: 13 additions & 0 deletions
13
...2.0/Solutions/Structural-pattern-solutions/organization-structure-management/reporting.js
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,13 @@ | ||
// reporting.js | ||
class Reporting { | ||
static generateReport(department) { | ||
console.log(department.getDetails()); | ||
} | ||
|
||
static generateEmployeeReport(employee) { | ||
console.log(employee.getDetails()); | ||
console.log("Tasks assigned:", employee.showTasks()); | ||
} | ||
} | ||
|
||
module.exports = Reporting; |