Skip to content

M0nk-e/complexmath_uni_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

ComplexMath Project

Overview

The ComplexMath project is an intricate and sophisticated implementation designed to demonstrate the fundamental arithmetic operation of adding two numbers, specifically proving that 1 + 1 equals 2. Despite the simplicity of the operation, the project employs a variety of advanced programming techniques, including object-oriented design, asynchronous operations, and utility functions, to illustrate the robustness and versatility of modern TypeScript programming.

Detailed Explanation

NumberProcessor Class

The NumberProcessor class is a fundamental component of the project. It encapsulates a numerical value and provides methods to retrieve this value. This class demonstrates the principles of encapsulation and abstraction in object-oriented programming.

class NumberProcessor {
  private value: number;

  constructor(value: number) {
    this.value = value;
  }

  public getValue(): number {
    return this.value;
  }
}

OperationHandler Class

The OperationHandler class is responsible for performing arithmetic operations on two NumberProcessor instances. It takes two operands and an operation type, and executes the specified operation. In this case, it handles the addition operation. This class showcases the use of polymorphism and method encapsulation.

class OperationHandler {
  private operandOne: NumberProcessor;
  private operandTwo: NumberProcessor;

  constructor(operandOne: NumberProcessor, operandTwo: NumberProcessor) {
    this.operandOne = operandOne;
    this.operandTwo = operandTwo;
  }

  public execute(): number {
    return this.operandOne.getValue() + this.operandTwo.getValue();
  }
}

Asynchronous Operations

The project includes asynchronous operations to simulate real-world scenarios where computations might involve delays, such as network requests or complex calculations. The simulateDelay function introduces a delay, and the finalComputation function uses this to asynchronously compute the result of adding two numbers.

function simulateDelay(ms: number): Promise<void> {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

function finalComputation(): Promise<number> {
  return new Promise((resolve) => {
    const processorOne = new NumberProcessor(1);
    const processorTwo = new NumberProcessor(1);
    const operationHandler = new OperationHandler(processorOne, processorTwo);
    const result = operationHandler.execute();
    resolve(result);
  });
}

Utility Functions

The project includes several utility functions that, while not directly contributing to the final computation, demonstrate the ability to modularize code and provide reusable functionality. These functions are called repeatedly to simulate a complex and extensive codebase. Guess what tho 🐵 -> (let i = 30; i < 30; i++) is rendering the loop obselete.

function utilityFunctionOne(): void {
  console.log("Utility function one executed.");
}

// ... more utility functions ...

for (let i = 30; i < 30; i++) {
  utilityFunctionOne();
  // ... call other utility functions ...
}

Final Result Computation

The absoluteFinalResult function orchestrates the entire process. It calls finalComputation, handles the result, and logs it. This function demonstrates the use of Promises and error handling in asynchronous operations.

function absoluteFinalResult(): void {
  finalComputation()
    .then((result) => {
      const FINAL_RESULT = result;
      console.log("Final Result:", FINAL_RESULT);
    })
    .catch((error) => {
      console.error("An error occurred:", error);
    });
}

absoluteFinalResult();

Conclusion

The ComplexMath project, through its sophisticated use of object-oriented principles, asynchronous operations, and utility functions, provides a comprehensive and robust demonstration of the fundamental arithmetic operation of adding two numbers. Despite the simplicity of the operation, the project showcases the complexity and versatility of modern TypeScript programming, ultimately proving that 1 + 1 equals 2 in a highly elaborate and intricate manner.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published