Skip to content

Core Concepts

This section explains the foundational components that define the MOFA Refined Architecture, which is designed to be a separate shared Dart package.

The central concept is the ‘Convertor’, a component that accepts a single input and computes a single output.

Components are chainable, meaning the output of one component becomes the input for the next. This allows the creation of modular pipelines similar to the functional programming paradigm found in rxdart.

Convertors are categorized into three main types based on their output type. This differentiation primarily facilitates various extensions for chaining, mapping, interceptors, and decoration.

  1. Basic Convertor: The output is a simple type T.
abstract class Convertor<To, From> {
To execute(covariant From from);
}
  1. StreamConvertor: The output is a Dart Stream<T>.
typedef StreamConvertor<To, From> = Convertor<Stream<To>, From>;
  1. AsyncConvertor: The output is a Dart Future<T>.
typedef AsyncConvertor<To, From> = Convertor<Future<To>, From>;

A Chain is a sequence of multiple Convertors queued together. The Chain itself acts as a single Convertor:

  • Its input type is the input type of the first Convertor.
  • Its output type is the output type of the last Convertor.

An Interceptor is a component that wraps a Convertor. Its purpose is to allow side effects without modifying the data flow.

  • It intercepts the input before the Convertor is executed.
  • It intercepts the output after the Convertor is executed.
  • Crucially, an Interceptor should not modify the input or the output.
  • The result of the wrapping is a new Convertor with the same input and output types as the wrapped one.

A Decorator wraps a Convertor and is used to allow modification of the input and/or output of that Convertor.

It offers the flexibility to:

  • Modify the input before it reaches the wrapped Convertor.
  • Modify the output after it’s returned.
  • Bypass the wrapped Convertor entirely.
  • Return a completely different output (of the same output type) without executing the original logic.