Chapter 5. Defining Contracts with Duck Typing
This chapter will illustrate an enhanced technique that allows us to define contracts between objects interacting each other. This technique, named duck typing, allows for implementing something similar to interfaces supported by many classical Object-Oriented Programming languages. The topics covered by the chapter are:
- Checking dynamic data types
- Contracts between software components
- Using duck typing
- Emulating interfaces with duck typing
Managing dynamic typing
Data types are one of the basic features that ensure consistency throughout an application. Some operations can be made only on specific data types and checking if a value is of a valid data type is crucial to avoid runtime exceptions. Most compiled ...
Get Mastering JavaScript Object-Oriented Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.