The Interface Segregation Principle

When designing the interface of an object, we should limit to define what is strictly necessary, avoiding carrying around stuff that is not used. This is, in a nutshell, the Interface Segregation Principle, whose official version says:

Clients should not be forced to depend on methods they do not use.

Although JavaScript does not support interfaces as abstract types to define contracts through a typing system, as we saw in Chapter 5, Defining Contracts with Duck Typing, it may somehow be emulated through Duck Typing. In any case, this principle does not refer to the interfaces as a pure syntactic element, but to the whole set of public properties and methods of an object.

In the definition of our object interfaces, ...

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.