liveBook · Manning

Business logic

As explained in Shipping Go: Develop, deliver, discuss, design, and go again

Business logic is the application logic that implements domain rules and required business behavior.

Business logic turns a business request into behavior the application can execute. In a translation service, it accepts a word and language, then returns the translated word. Keeping this work in a service separates it from handlers and servers, making the behavior easier to test. section 3.1

Define the logic as a small, observable unit:

  • Give the service a clear input boundary: a word and a language. section 3.1
  • Return an output that represents the required business result. section 3.1
  • Capture expected behavior with given-when-then cases before expanding the implementation. section 3.1

A testable translation service

A minimal Go function such as Translate(word string, language string) string gives the business behavior a boundary. Tests can then check English translation, capitalization, and extra spaces without testing the whole server. section 3.1

Listing 3.2 translator.go
package translation        #1
 
func Translate(word string, language string) string {
    return ""              #2
}

Use the small translator.go listing as a starting point for isolating business behavior from the application entry point. section 3.1

How Shipping Go: Develop, deliver, discuss, design, and go again covers it

How deep it goes
Defines a small service boundary and test cases, but stops short of detailing complex domain rules or implementation internals.
Examples
Uses a translation service, Translate function, and cases for English, capitalization, and extra spaces.
What you can do after
Diagnose behavior by isolating the service and asserting outputs against given-when-then cases.
How it connects
Connects business logic with services, handlers, servers, unit testing, and behavior-driven development.

Also explained in

Compare how 10 books explain business logic →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Shipping Go: Develop, deliver, discuss, design, and go again. The section links point to the parts of the book it draws on.