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 classes and interfaces from the object-oriented programming (OOP) perspective. OOP is a programming style where your programs are about handling objects rather than being a composition of actions (think functions). Of course, some of these 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 API on classes. Also, you can often hear the phrase "program to interfaces" in conversations of programmers. In this chapter, we’ll explain what it means. In short, this chapter is a whirlwind tour of OOP using TypeScript.

3.1  Working with classes

Let’s recap what we know about TypeScript classes from chapter 2:

3.1.1  Getting familiar with class inheritance

 

3.1.2  Access modifiers public, private, protected

 
 
 

3.1.3  Static variables and a singleton example

 
 

3.1.4  The method super() and the keyword super

 
 
 

3.1.5  Abstract classes

 
 
 

3.1.6  Method overloading

 
 
 
 

3.2  Working with interfaces

 
 
 
 

3.2.1  Enforcing the contract

 

3.2.2  Extending interfaces

 
 

3.2.3  Programming to interfaces

 
 

3.3  Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest