Chapter 3. Object-oriented programming with classes and interfaces

 

This chapter covers

  • How class inheritance works
  • Why and when to use abstract classes
  • How interfaces can force a class to have methods with known signatures without worrying about implementation details
  • What “programming to interfaces” means

In chapter 2, we introduced classes and interfaces for creating custom types. In this chapter, we’ll continue learning about classes and interfaces from the object-oriented programming (OOP) perspective. OOP is a programming style where your programs focus on handling objects rather than on composing actions (think functions). Of course, some of those functions would create objects as well, but in OOP, objects are the center of the universe.

Developers who work with object-oriented languages use interfaces as a way to enforce certain APIs on classes. Also, you can often hear the phrase “program to interfaces” in the conversations of programmers. In this chapter, we’ll explain what that means. In short, this chapter is a whirlwind tour of OOP using TypeScript.

3.1. Working with classes

Let’s recap what you learned about TypeScript classes in chapter 2:

3.2. Working with interfaces

Summary

sitemap