DEV Community

Discussion on: Static Class or Interface?

Collapse
 
nektro profile image
Meghan (she/her)

Static class: A Class that can be not instantiated into an Object and only contains functions and other statically accessible declarations.

An Interface: is an extension template you can add on to classes to say what methods they might contain. Say you have a Drivable interface that exposes a .drive method. This interface does not contain an implementation but Car, Truck, and SUV, all implement the Drivable interface. Interfaces come in handy when you want to define a parameter type that doesn't need to know about the implementation, but only that a particular set of methods. The best example of this the the List. You might get a List that uses an array or linked list, but in most cases you just need something you can .push, .pop, .shift, and .unshift to.