Use case as a UI context
Today I was implementing some feature using “use case as object” approach – where use case tells a story about interactions between actor and domain entities. It’s a simple object with few methods and each of those methods is invoked as a result of control flow or interaction via UI or services. It should emanate actions at the same abstraction level, so higher use cases can use lower ones.
It’s obvious that use case gives you some context – in Buying use case it could be Shop context (or buying because maybe distinction between context and use case is not needed). Those contexts can divide actor definition into raw “common-abilities-and-data” model and roles that actor can take. That’s how I understand DCI approach.
But your app is not only domain logic, but also has some UI layer to get some interactions with real user. As a presentation layer it should show current state of application, current context. So why don’t we bind UI to use case with something like controller – use case doesn’t know anything about UI, and UI presents state of use case. I mean if some component is hidden in this use case’s context it should be hidden by this controller. If current use case disables some paths they should be presented as disabled.
Ok, but what about all the “view should present domain models” stuff? My first thought was – maybe view changes, in DCI approach, are triggered by use case actions, not by domain entities, like in classic MVC? So they should present current context (within use case), probably with shared presentation behaviours extracted for reuse.
Or… Maybe views should still present current domain entities states, but also with their abilities in current context. So extending domain entity with role would trigger view changes to present roles behaviours.
Currently I’m not sure which way is good – I’ve written some production code with view-as-use-case-state-presentation and it seems nice, but second approach looks also interesting. What are your thoughts about that?