5-TS OOP: Abstract Classes
Tags: javascript, oop, typescript
Published: 2022-11-19 17:50:38

---
title: 5-TS OOP: Abstract Classes
published: true
description: 
series: jstsoop
tags: javascript, oop, typescript
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zos5nakqvs90vdfpord.png
# Use a ratio of 100:42 for best results.
# published_at: 2022-10-25 09:51 +0000
---

## Introduction

Abstract classes are classes that cannot be instantiated, they are used as a base class for other classes, they can contain abstract methods and concrete methods.

That's the academic definition, let's simplify it.

Imagine `Abstract classes` like something that is only a definition, but it can not be existing by itself, for example, `Fruit` is a concept of something sweet (Mostly) that can be eaten from plants, it does not exist as an entity, but `Mango` is a kind of `fruit` that exists as an entity, it is a real thing, it can be eaten, it can be thrown, it can be used in many ways, but `Fruit` is just a concept, it is not a real thing, it is just a definition.

From this point we can say `Fruit` is an abstract class, and `Mango` is a concrete class AKA the thing that makes `Fruit` a real thing.

Abstract classes `can not be instantiated`, they can only be `inherited` from, and they can contain abstract methods (methods that are not implemented) and concrete methods (methods that can be called and implemented by the class itself).

## Abstract Class In Javascript

Unfortunately, Javascript does not have abstract classes, but luckily `Typescript` does, that's why i mentioned it in the title, and this course will cover OOP in both `Javascript` and `Typescript`.

I will just explain the concept of abstract in Typescript, you don't really need to have an experience in Typescript to follow up with me, you can just follow the code examples and you will be fine.

## Abstract Class In Typescript

Let's see an example in TS:

```ts
abstract class Fruit {
    name: string;
    taste: string;
    color: string;
}

class Mango extends Fruit {
    name = 'Mango';
    taste = 'Sweet';
    color = 'Yellow';
}
```

Here we have 2 classes, the `Fruit` class is the abstract class, and the `Mango` class is the concrete class.

So the class that extends the abstract class is called `concrete` class, and the abstract class is the `base` class.

## Abstract class characteristics

Here are the characteristics of an abstract class:

* Abstract classes `can not be instantiated`, (you can not create a new object of it).
* Abstract classes `can only be inherited from`.
* Abstract classes `can contain abstract methods` and `concrete methods`, (We will discuss it in the next article)

So in a nutshell, abstract classes are classes that can not be instantiated (`A.K.A` can not exist by its own), they are used as a base class for other its children classes, they can contain abstract methods and concrete methods.

## 🎨 Conclusion

In this article we learned about abstract classes, we learned what is an abstract class, what are the characteristics of an abstract class, and we learned that abstract classes are classes that can not be instantiated, they are used as a base class for other its children classes, they can contain abstract methods and concrete methods.

## ☕♨️ Buy me a Coffee ♨️☕

If you enjoy my articles and see it useful to you, you may [buy me a coffee](https://www.paypal.com/paypalme/hassanzohdy), it will help me to keep going and keep creating more content.

## 😍 Join our community

Join our community on [Discord](https://discord.gg/uBh98KZGGF) to get help and support.

## 📚 Bonus Content 📚

You may have a look at these articles, it will definitely boost your knowledge and productivity.

General Topics

* [Event Driven Architecture: A Practical Guide in Javascript](https://dev.to/hassanzohdy/event-driven-architecture-the-best-paradigm-that-i-love-to-work-with-in-javascript-and-node-js-1gnk)
* [Best Practices For Case Styles: Camel, Pascal, Snake, and Kebab Case In Node And Javascript](https://dev.to/hassanzohdy/best-practices-for-case-styles-camel-pascal-snake-and-kebab-case-in-node-and-javascript-55oi)
* [After 6 years of practicing MongoDB, Here are my thoughts on MongoDB vs MySQL
](https://dev.to/hassanzohdy/after-6-years-of-practicing-mongodb-here-are-my-thoughts-on-mongodb-vs-mysql-574b)

Packages & Libraries

* [Collections: Your ultimate Javascript Arrays Manager](https://dev.to/hassanzohdy/collections-your-ultimate-javascript-array-handler-3o15)
* [Supportive Is: an elegant utility to check types of values in JavaScript](https://dev.to/hassanzohdy/supportive-is-an-elegant-utility-to-check-types-of-values-in-javascript-1b3e)
* [Localization: An agnostic i18n package to manage localization in your project](https://dev.to/hassanzohdy/mongez-localization-the-simplest-way-to-translate-your-website-regardless-your-favorite-framework-4gi3)

 React Js Packages

* [useFetcher: easiest way to fetch data in React Js](https://dev.to/hassanzohdy/usefetcher-the-easiest-way-to-fetch-data-in-react-45o9)

Courses (Articles)

* [ES6++: The Ultimate Guide to ES6 and Beyond](https://dev.to/hassanzohdy/es6-1-introduction-h3e)
* [Node Js 2023 Course: Node With Typescript, The Ultimate Guide](https://dev.to/hassanzohdy/nodejs-course-2023-introduction-to-nodejs-3n4e)
* [React Js: Let"s Create File Manager With React Js and Node Js](https://dev.to/hassanzohdy/lets-create-a-file-manager-from-scratch-with-react-and-typescript-chapter-i-a-good-way-to-expand-your-experience-5g4k)