CodeBlanks Logo Icon CodeBlanks

Project design

Design the skeleton of the expert final mini app.

Project design

In the expert final we will build a small native math service. The goal is to combine FFI, code generation and architecture patterns in a real mini application.

In this lesson we design the skeleton: an abstract MathService class and an int add(int a, int b) contract method. The next lessons add FFI binding, code generation, repository and DI layers.

Each lesson's initial code includes the previous lesson's solution; so you grow the project step by step. In the final lesson all parts come together in a MathApp shell.

The service contract

MathService is the project's core contract. The int add(int a, int b) method adds two integers. This abstract class is the common interface for both FFI-based and mock implementations.

The advantage of an abstract class: main depends on the interface, not the concrete class. In the next lessons NativeMathService (FFI) and mock services for tests will implement the same interface.

This separation follows the dependency inversion principle: the high-level module (main) depends on the interface, not the low-level (concrete service). Changes are localized.

Practice Build the MathService skeleton

Define an abstract class MathService with an int add(int a, int b); abstract method. In main add print('service ready');.

Starter code

main.dart
void main() {
  // define an abstract MathService class (add method)
  // print service ready in main
}

Sample solution

main.dart
abstract class MathService {
  int add(int a, int b);
}

void main() {
  print('service ready');
}

Expected output

service ready

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the goal of this project?

  • Only open a database
  • Only draw UI
  • Only write tests
  • Combine FFI, codegen and architecture Correct answer

Explanation: the project combines three expert topics in a real app.

2 The abstract class keyword

Question
____ class MathService {
  int add(int a, int b);
}
Answer
abstract class MathService {
  int add(int a, int b);
}

Explanation: abstract class defines a contract.

3 Match the contract parts

Term Meaning
MathService Abstract service
add(int, int) Add contract
main Entry point
abstract Abstraction keyword

All lessons in Expert