{"id":24528910,"url":"https://github.com/mohi-uddin-akbar/typescript-oop-concepts","last_synced_at":"2026-04-13T03:34:23.164Z","repository":{"id":248561253,"uuid":"828046919","full_name":"MOHI-UDDIN-AKBAR/typeScript-OOP-concepts","owner":"MOHI-UDDIN-AKBAR","description":"Explore the fundamentals and advanced aspects of TypeScript with a focus on Object-Oriented Programming (OOP) concepts. Dive into abstract classes, inheritance, interfaces, generics, access modifiers, and more. This repository serves as a comprehensive guide to leveraging TypeScript for robust and maintainable software development.","archived":false,"fork":false,"pushed_at":"2024-07-15T16:55:18.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-28T12:46:34.491Z","etag":null,"topics":["abstract-classes","access-modifiers","generics","inheritance","oop","programming-concepts","setters-and-getters","software-development","static-methods","typescript","typescript-classes","typescript-interfaces"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MOHI-UDDIN-AKBAR.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-13T01:20:39.000Z","updated_at":"2024-12-09T19:04:16.000Z","dependencies_parsed_at":"2024-07-15T20:25:18.942Z","dependency_job_id":null,"html_url":"https://github.com/MOHI-UDDIN-AKBAR/typeScript-OOP-concepts","commit_stats":null,"previous_names":["mohi-uddin-akbar/typescriptoopconcepts","mohi-uddin-akbar/typescript-oop-concepts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MOHI-UDDIN-AKBAR/typeScript-OOP-concepts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHI-UDDIN-AKBAR%2FtypeScript-OOP-concepts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHI-UDDIN-AKBAR%2FtypeScript-OOP-concepts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHI-UDDIN-AKBAR%2FtypeScript-OOP-concepts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHI-UDDIN-AKBAR%2FtypeScript-OOP-concepts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MOHI-UDDIN-AKBAR","download_url":"https://codeload.github.com/MOHI-UDDIN-AKBAR/typeScript-OOP-concepts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHI-UDDIN-AKBAR%2FtypeScript-OOP-concepts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281441021,"owners_count":26501758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-classes","access-modifiers","generics","inheritance","oop","programming-concepts","setters-and-getters","software-development","static-methods","typescript","typescript-classes","typescript-interfaces"],"created_at":"2025-01-22T07:33:15.086Z","updated_at":"2025-10-28T12:46:35.977Z","avatar_url":"https://github.com/MOHI-UDDIN-AKBAR.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScriptOOPConcepts\n\nThis repository contains various examples of Object-Oriented Programming (OOP) principles implemented in TypeScript. The examples cover abstract classes, access modifiers, basic class usage, generics, inheritance, setters and getters, static properties and methods, and the use of interfaces with classes.\n\n## Table of Contents\n\n- [Abstract Class](#abstract-class)\n- [Access Modifiers](#access-modifiers)\n- [Basics of Classes](#basics-of-classes)\n- [Generics with Class](#generics-with-class)\n- [Inheritance](#inheritance)\n- [Setters and Getters](#setters-and-getters)\n- [Static Class](#static-class)\n- [Interface with Class](#interface-with-class)\n\n## Abstract Class\n\nThe `Profile` class is an abstract class that represents a profile with common properties and behaviors. The `Facebook` class extends this abstract class and provides a specific implementation of the `getProfile` method.\n\n```typescript\nabstract class Profile {\n  name: string;\n  email: string;\n  sex: string;\n\n  constructor(name: string, email: string, sex: string) {\n    this.name = name;\n    this.email = email;\n    this.sex = sex;\n  }\n\n  abstract getProfile(): void;\n}\n\nclass Facebook extends Profile {\n  constructor(name: string, email: string, sex: string) {\n    super(name, email, sex);\n  }\n\n  getProfile(): void {\n    console.log(`Name: ${this.name}\\nEmail: ${this.email}\\nSex: ${this.sex}`);\n  }\n}\n\nconst arafat = new Facebook(\"Arafat\", \"arafat@gmail.com\", \"male\");\narafat.getProfile();\n```\n\n## Access Modifiers\n\nThe `Animal` class demonstrates the use of public, private, and protected access modifiers. The `Dog` class extends `Animal` and provides additional functionality.\n\n```typescript\nclass Animal {\n  public name: string;\n  private age: number;\n  protected country: string;\n\n  constructor(name: string, age: number, country: string) {\n    this.name = name;\n    this.age = age;\n    this.country = country;\n  }\n\n  protected getName(): string {\n    return this.name;\n  }\n\n  public setAge(modifiedAge: number): void {\n    if (typeof modifiedAge === \"number\") {\n      this.age = modifiedAge;\n    }\n  }\n\n  protected getDetails(): { name: string; age: number; country?: string } {\n    if (this.country \u0026\u0026 this.country.length !== 0) {\n      return { name: this.getName(), age: this.age, country: this.country };\n    }\n    return { name: this.getName(), age: this.age };\n  }\n}\n\nclass Dog extends Animal {\n  private sex: string;\n\n  constructor(name: string, age: number, country: string, sex: string) {\n    super(name, age, country);\n    this.sex = sex;\n  }\n\n  aboutDog(): void {\n    const { name, age, country } = this.getDetails();\n    let locationInfo = \"\";\n    if (country \u0026\u0026 country.length !== 0) {\n      locationInfo = `, from ${country}`;\n    }\n    console.log(`${name} is ${age} years old${locationInfo}, sex ${this.sex}`);\n  }\n}\n\nconst dog = new Dog(\"Lucy\", 2, \"Poland\", \"female\");\nconsole.log(dog); // Only displays public properties\ndog.aboutDog(); // Displays detailed information\ndog.setAge(3);\nconsole.log(dog); // Again, only displays public properties\n```\n\n## Basics of Classes\n\nThe `Person` class demonstrates basic class usage with methods to get and set properties.\n\n```typescript\nclass Person {\n  name: string;\n  age: number;\n\n  constructor(name: string, age: number) {\n    this.name = name;\n    this.age = age;\n  }\n\n  aboutPerson(): void {\n    console.log(`${this.name} is ${this.age} years old.`);\n  }\n\n  getName(): string {\n    return this.name;\n  }\n\n  setName(newName: string): void {\n    if (typeof newName === \"string\" \u0026\u0026 newName.trim().length \u003e 0) {\n      this.name = newName;\n    } else {\n      console.error(\"Cannot initialize empty string as name\");\n    }\n  }\n}\n\nconst samir: Person = new Person(\"Samir\", 27);\nconsole.log(JSON.stringify(samir)); // Log the entire object\nconsole.log(samir.getName()); // Get the name property\nsamir.setName(\"Samir Khan\"); // Set a new name\nconsole.log(JSON.stringify(samir)); // Log the updated object\nsamir.aboutPerson(); // Print person details\n```\n\n## Generics with Class\n\nThe `Box` class is a generic class that encapsulates a value of any type, with type safety.\n\n```typescript\nclass Box\u003cT\u003e {\n  private _value: T;\n\n  constructor(value: T) {\n    if (\n      typeof value !== \"object\" ||\n      typeof value !== \"string\" ||\n      typeof value !== \"number\"\n    ) {\n      this._value = value;\n    } else {\n      throw new Error(\"Complex objects are not supported\");\n    }\n  }\n\n  getValue(): T {\n    return this._value;\n  }\n}\n\nconst userName = new Box\u003cstring\u003e(\"Samir\");\nconsole.log(userName.getValue());\nconst userId = new Box\u003cnumber\u003e(101);\nconsole.log(userId.getValue());\nconst user = new Box\u003c{ userName: string; userId: number }\u003e({\n  userName: \"Samir\",\n  userId: 101,\n});\nconsole.log(user.getValue());\n```\n\n## Inheritance\n\nThe `Student` class represents a student, and the `Grade` class extends it, adding a grade property.\n\n```typescript\nclass Student {\n  name: string;\n  id: number;\n\n  constructor(name: string, id: number) {\n    this.name = name;\n    this.id = id;\n  }\n\n  getName(): string {\n    return this.name;\n  }\n}\n\nclass Grade extends Student {\n  grade: number;\n\n  constructor(name: string, id: number, grade: number) {\n    super(name, id);\n    this.grade = grade;\n  }\n\n  getInfo(): { name: string; id: number; grade: number } {\n    return { name: this.getName(), id: this.id, grade: this.grade };\n  }\n}\n\nconst rifat = new Grade(\"Rifat\", 101, 4.5);\nconsole.log(rifat);\nconsole.table(rifat.getInfo());\n```\n\n## Setters and Getters\n\nThe `Dorm` class uses a getter and setter to manage the number of students.\n\n```typescript\nclass Dorm {\n  name: string;\n  location: string;\n  amountOfStudents: number;\n\n  constructor(name: string, location: string, amountOfStudents: number) {\n    this.name = name;\n    this.location = location;\n    this.amountOfStudents = amountOfStudents;\n  }\n\n  setCurrentAmountOfStudents(students: number): void {\n    if (students \u003e= 0) {\n      this.amountOfStudents = students;\n    } else {\n      console.error(\"Number of students must be positive.\");\n    }\n  }\n\n  get infoAboutDorm(): string {\n    return `${this.name} is a popular dorm located at ${\n      this.location\n    }. Almost ${this.amountOfStudents.toLocaleString()} students currently live in this dorm.`;\n  }\n}\n\nconst amio = new Dorm(\"Amio\", \"Poland\", 1110);\nconsole.log(amio);\namio.setCurrentAmountOfStudents(1500); // Use setter to update the property\nconsole.log(amio.infoAboutDorm);\n```\n\n## Static Class\n\nThe `Calculation` class demonstrates the use of static properties and methods.\n\n```typescript\nclass Calculation {\n  static PI: number;\n  constructor(PI: number) {\n    Calculation.PI = PI;\n  }\n  static circleArea(radius: number): number {\n    return Calculation.PI * (radius * radius);\n  }\n}\n\nconst area = new Calculation(3.1416);\nconsole.log(Calculation.PI);\nconsole.log(Math.round(Calculation.circleArea(3)));\n```\n\n## Interface with Class\n\nThe `IUser` interface is implemented by the `User` class to ensure a specific structure.\n\n```typescript\ninterface IUser {\n  name: string;\n  age: number;\n  universityName: string;\n  getDetails(): void;\n}\n\nclass User implements IUser {\n  name: string;\n  age: number;\n  universityName: string;\n\n  constructor(name: string, age: number, universityName: string) {\n    this.name = name;\n    this.age = age;\n    this.universityName = universityName;\n  }\n\n  getDetails(): void {\n    console.log(\n      `${this.name} got admission at ${this.universityName} within ${this.age}`\n    );\n  }\n}\n\nconst adil = new User(\"Adil Khan\", 15, \"University of Krakow\");\nadil.getDetails();\n```\n\n## Running the Examples\n\nTo run these examples, you need to have TypeScript installed. Follow these steps:\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/MOHI-UDDIN-AKBAR/TypeScriptOOPConcepts.git\n   cd TypeScriptOOPConcepts\n   ```\n\n2. Install TypeScript if you haven't already:\n\n   ```bash\n   npm install -g typescript\n   ```\n\n3. Compile the TypeScript files:\n\n   ```bash\n   tsc\n   ```\n\n4. Run the resulting JavaScript files using Node.js:\n   ```bash\n   node path/to/compiled/file.js\n   ```\n\nReplace `path/to/compiled/file.js` with the path to the compiled JavaScript file you want to run\n\n.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohi-uddin-akbar%2Ftypescript-oop-concepts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohi-uddin-akbar%2Ftypescript-oop-concepts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohi-uddin-akbar%2Ftypescript-oop-concepts/lists"}