TypeScript 3 Fundamentals, v2 Abstract Classes
This course has been updated! We now recommend you take the TypeScript Fundamentals, v3 course.
Transcript from the "Abstract Classes" Lesson
>> Mike North: This, I kinda feel abrogated to show you this although I don't find that I use it all that often, abstract classes. Abstract classes cannot be instantiated directly, they just serve as base classes. So unlike in interface, which also can't be instantiated, abstract classes can have implementations, right?
[00:00:21] In this case, I have a constructor with some param properties ,so name and email will be there, it's serving as a base class. But I also have an abstract method here, and that must be implemented by any subclass. So I think of this as sort of half class, half interface.
[00:00:40] And this lets us pass around. We can still refer two things by their abstract base class. But concrete implementations may look very, very different. All you have to do here is make the class abstract and then you can make both fields and methods abstract as well. And so classes are required to implement those with a compatible access modifier.
[00:01:05] Like, you could take something protected, I wonder if you can even do that.
>> Mike North: Yep.
>> Mike North: No, it looks like that they've fixed this here. So gotta make things public because it'd be kinda strange to have abstract things that are private, like how? You don't really have visibility into subclasses in that way.
[00:01:31] So here's an example of an implementation, and you can see, if we were to remove sendEmail, it's gonna tell us, non-abstract class, ConcreteContact, does not implement inherited inherited abstract member sendEmail. So we have not met all of the requirements we need to meet.