mercredi 9 juin 2021

Update work-item state using enum or create specific methods for updating work-item state

Statement:

There are two choices:

WorkItemState is an emum and can be : SCHEDULED, READY, SUBMITTED, EXECUTING, COMPLETED

  1. Create single method : updateWorkItemState(workItemId, workItemState)
  2. Create multiple methods : markAsCompleted(workItemId), markAsSubmitted(workItemId), markAsExecuting(workItemId) etc.

In first approach, I am exposing work item states to client while in second approach I have to create multiple methods i.e one for each state.

I also have to check that state transition can be applied only if current state is valid. Ex- If work item is in EXECUTING state, then only it can be completed.

Which of the two approach seems better in terms of readability, maintainability and extensibility?

Aucun commentaire:

Enregistrer un commentaire