Search⌘ K
AI Features

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...

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:

  1. Go into src/museums/types.ts, and create a type that defines a Museum:
TypeScript 3.3.4
export type Museum = {
id: string,
name: string,
description: string,
location: {
lat: string,
lng: string
}
}

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.

  1. Inside src/museums/types.ts, create an interface that will define MuseumController. It should contain a method that lists all the museums:
TypeScript 3.3.4
export interface MuseumController {
getAll: () => Promise<Museum[]>;
}
  1. Inside src/museums/controller.ts, create a class that will act as the controller. It should contain a function named getAll. In the future, this is where the business logic will live, but for now, we can return an empty array: