Member-only story

How we boost javascript productivity of MVC pattern by adopting a BDD-like development strategy

Kok Hang Cheng
3 min readMay 1, 2021

--

MVC pattern is highly encouraged in modern web development because it encouraged developers to separate entities, logics and the way of display.

Take a look at what it is like if we adopted the MVC pattern to develop a Add User feature for a user management system. The following code modified from a template of express-typescript-generator.

The codes itself is simple: get parameters from the request body, validate it and then save the entities if it passes the validation.

The above example works fine. But we can make some changes to improve the code in terms of reusability, readability and testability.

The code itself tightly coupled with the controller, which means the logic can only use for an API call. What if we want to use socket.io / create a user in another function? To solve this problem, we can move all the logic to a handler function:

--

--

Kok Hang Cheng
Kok Hang Cheng

Written by Kok Hang Cheng

a little philosopher in the IT world :P

No responses yet