Developing the Business Logic
Understand how to create business logic in a Deno web application by defining types, interfaces, and controllers. Explore best practices like dependency inversion to keep code modular and testable while preparing your app for future data integration.
We'll cover the following...
We'll cover the following...
Steps to develop a business logic
Previously, we stated that our business logic is the most important part of our application. Even though ours will be super simple for now, that’s what we’ll develop first.
Since we’ll be using TypeScript for our application, let’s define our Museum object. Follow these steps:
- Go into
src/museums/types.ts, and create a type that defines aMuseum:
Make sure it’s exported because we’ll be using this across other files.
Now that we know the type, we must create some business logic to get a list of museums.
- Inside
src/museums/types.ts, create an interface that will defineMuseumController. It should contain a method that lists all the museums:
- Inside
src/museums/controller.ts, create a class that will act as the controller. It should contain a function namedgetAll. In the future, this is where the business logic will live, but for now, we can return an empty array: