Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Polymorphism

Polymorphism is the ability to present the same interface for differing underlying forms (data types). Polymorphism is often referred to as the third pillar of object-oriented programming, after encapsulation and inheritance.

Polymorphism is what enabled us to implement the LSP in the preceding section:

class AreaCalculator { 
    public area(shapes: Shape[]) { 
        return shapes.reduce( 
            (p, c) => p + c.area(), 
            0 
        ); 
    } 
} 

Objects of the derived class (Circle and Rectangle) may be treated as objects of a base class (Shape) in places such as method parameters (such  as the area method). Base classes may define and implement abstract methods, and derived classes can override them, which means they provide their definition and implementation. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content