Reading 8: Defining ADTs with Interfaces, Generics, Enums, and Functions
We also discuss subtyping as a relationship between two types determined by their specs, and distinguish it from subclassing, which involves reps as well. After today’s class, you should be able to: TypeScript’s interface is a useful language mechanism for expressing an abstract data type. An interface in TypeScript is a list of method signatures without method bodies. A class implements an interface if it declares the interface in its implements clause, and provides method bodies for all of the interface’s methods. So one way to define an abstract data type in TypeScript is as an interface. The type’s implementation is then a class implementing that interface. One advantage of this approach is that the interface can specify the contract for the client and nothing more. The interface is all a client programmer needs to read to understand the ADT. The client can’t create inadvertent dependencies on the ADT’s rep, because the rep isn’t present in the interface (not even as private fields
Reading 8: Defining ADTs with Interfaces, Generics, Enums, and Functions Reading 8: Defining ADTs with Interfaces, Generics, Enums, and Functions Praxis Tutor exercises Keep making progress on TypeScript by completing the following categories in the Praxis Tutor: ✓ Object 2/2 ✓ Interfaces & Enums 1/1 Software in 6.102 Safe from bugs Easy to understand Ready for change Correct today and correct in the unknown future. Communicating clearly with future programmers, including future you. Designed to accommodate change without rewriting. Objectives Today’s class is about various ways to implement a
Explore this link on the map →related reading
- Reading 12: Defining ADTs with Interfaces, Generics, Enums, and Functionsweb.mit.edu
- Reading 10: Abstract Data Typesweb.mit.edu
- Reading 6: Abstract Data Typesweb.mit.edu
- Defining Shared Behavior with Traits - The Rust Programming Languagedoc.rust-lang.org
- Reading 11: Recursive Data Typesweb.mit.edu
- TypeScript: Documentation - Genericstypescriptlang.org
- TypeScript: Documentation - Classestypescriptlang.org
- TypeScript: Documentation - TypeScript 3.7typescriptlang.org
- TypeScript: Documentation - Object Typestypescriptlang.org
- Reading 2: Basic TypeScriptweb.mit.edu
- TypeScript: Documentation - The Basicstypescriptlang.org
- Reading 17: Recursive Data Typesweb.mit.edu