As I delve into writing TypeScript for my Angular project, one burning question arises — should I use an Interface or a Class to create my domain objects? My quest is to uncover solid data regarding the actual implications of opting for the Class route.
I'm aware that utilizing an interface doesn't result in any generated JavaScript code, whereas employing a Class does. Both methods offer advantages such as autocompletion and syntax validation.
Personally, I lean towards using classes due to various reasons: - Facilitates unit testing - Enables embedding business logic within domain objects (especially beneficial for adhering to Domain Driven Design) - Allows enforcement of immutability on domain objects
Hence, theoretically speaking, interfaces might be more cost-effective. However, my main conundrum lies in determining whether the drawbacks of using classes indeed overshadow the benefits they bring.
To this end, I am keen to learn about others' experiences in comparing these two approaches within practical applications. Additionally, insights from performance tests conducted in this realm would be greatly appreciated.
Thus far, my research led me to stumble upon a related query (classes vs interfaces in Angular(TypeScript)) suggesting the preference for interfaces when dealing with data models, yet it lacks concrete evidence to aid in making an informed decision.