Your final project delivery will be to do npm -publish of your TypeScript code which you will now write based on the UML diagram you made of your team’s Assigned Business Domain.
By the end of this lab, you will be able to convert UML class diagrams into TypeScript code, implement inheritance and composition, and create working examples of a simple domain model.
Prerequisites
Basic understanding of UML class diagrams
Visual Studio Code or any TypeScript-compatible IDE
Node.js and npm installed
Part 1: Basic Class Creation
Let's start with a simple UML class and convert it to TypeScript.
UML:
Copy
+-------------------+
| Person |
+-------------------+
| - name: string |
| - age: number |
+-------------------+
| + getName(): string
| + getAge(): number |
+-------------------+
TypeScript:
typescript
Copy
class Person {
private name: string;
private age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
public getName(): string {
return this.name;
}
public getAge(): number {
return this.age;
}
}
// Usage
const person = new Person("John Doe", 30);
console.log(person.getName()); // Output: John Doe
console.log(person.getAge()); // Output: 30
Part 2: Inheritance
Now, let's implement inheritance using a Student class that extends Person.