Use case internals

Use Case Internals

What is a use case?

Part of Hexagonal Architecture is the concept of the Application Boundary. This boundary separates our application as a whole from everything else (both framework and communication with the outside world).

A Use Case (sometimes called a Command) is an explicitly defined way in which an application can be used.

We define how the outside world can communicate with our application by creating "Use Cases". These essentially are classes which name actions that can be taken. For example, our CreatePostUsecase defines that our application can create a post.

Defining Use Cases has some useful side-affects. For example, we clearly and explicitly can see how our application "wants" to be interacted with. We can plan use cases ahead of time, or add them as needed, but use cases should capture the operations which can happen within our application.

Aside: Platform uses some generic CRUDS usecases. These aren't tied to a specific Domain Model (Entity) ie. a Post but rather have the entity and repo injected into them. This makes Use Cases significantly less well defined. A developer can no longer glance at the Use Case directory and see what actions are available. This might be something we can improve in future

Anatomy of a Use Case (in platform)

Use Cases in platform all follow a high level interface. In short they all have a interact() method.

interface Usecase
{
/**
* @return Array
*/
public function interact();
}

To enable building of some generic use cases they also have isSearch and isWrite methods.

interface Usecase
{
/**
* Will this usecase write any data?
*
* @return Boolean
*/
public function isWrite();
​
/**
* Will this usecase search for data?
*
* @return Boolean
*/
public function isSearch();
​
/**
* @return Array
*/
public function interact();
}

The actual parameters for each UseCase are injected through setter methods, commonly: setPayload(), setIdentifiers and setFilters.

CRUDS use cases

Most of our use cases follow 5 high level patterns for Create, Read, Update, Delete and Search (CRUDS)

Create

Create Usecase

​create​

Create Usecase - Collaborators

​collaborators

Read

Read Usecase

​read

Update

Update Usecase

​update​

Delete

Delete Usecase

​delete​

Search Usecase

​search​