Matt Vaughn
Nov 26, 2019 · 1 min read

If you are using an interface to define a shape/schema for some data and you are creating Object literals to represent that data — Why not use a class? You get a constructor, you can validate the input, you can overload the constructor, you can use getters/setters, the class can inherit from a base class and also implement multiple interfaces? Is it really an interface, if nothing ever implements it? My thoughts on this are more from a C#/Java/.NET usage of interfaces and the OOP definitions.

I know it is a common practice in TypeScript/JS apps to use this technique to define shapes. I just prefer a class especially when you have to create an object with that data shape. There is nothing wrong with instantiating a class — Object literals work, but I prefer classes.

    Matt Vaughn

    Written by

    I love tacos, code, jazz, my husky and maybe 3 people in this world...and of course: Angular. Angularlicious podcast — more info at http://angularlicio.us