An Operation object defines intrinsically either how a query must be forwarded to a data source either how data must be manipulated, containing inside all parameters required to execute it.

The base definition of an operation is empty, as this object must be customized in custom objects.

sealed class Operation

For example, if repositories want recover from a data source failure N times, we could define a custom operation to let repositories know how to behave. The representation of this operation could be:

data class RecoverOperation(val retries: Int): Operation()
// retrieve a book and try to recover only once if failure
bookRepository.get(IdQuery(42), RecoverOperation(1))

Default implementations

Harmony provides multiple predefined operations ready to be used. The most popular are:

  • DefaultOperation: Empty operation. To be used when none operation is required or as a default behavior.

All repositories must have a default behavior by supporting the DefaultOperation.