DEV Community

Discussion on: The Bridge Pattern - Design Patterns meet the Frontend

Collapse
 
jwp profile image
John Peters • Edited

In traditional Javascript there is no guarantee that the service you show, can know ahead of time if both objects (shown above) have implemented the getter pattern. It would only become known at runtime.

This is my #1 reason for advocating class design with types, and why I prefer Typescript over Javascript.

If we use typed classes, then the question is answered before compile time via intellisense. If either of the objects passed in did not implement getters the red squiggly line would show via intellisense while coding.

Therfore questions like 'how do we know' are answered by Intellisense. It's perhaps the greatest tool for programmers ever; and it works best on Typed objects.

Thread Thread
 
oliverradini profile image
OliverRadini

Indeed, and I'm also a big fan of Typescript; I think the question of catching at runtime vs compile time is a separate question, though.

My main point was that it isn't really possible to assert that Javascript developers don't use abstract declarations. That's all they use.