Option 2 would lead to a process code for sure. It may be easier to develop, but much harder to maintain.
Now in the real world this is a pure administration task
The "administration" of tasks should be closed and called through publicly available, fully "domain" actions. Preferably, it is still written in easy-to-understand code that is called from a domain.
As I see it, the problem is that UndoLastStatus does not make sense to a domain expert.
Rather, they talk about making, canceling, and filling out orders.
Something along these lines might fit better:
class Order{ void CancelOrder(){ Status=Status.Canceled; } void FillOrder(){ if(Status==Status.Canceled) throw Exception(); Status=Status.Filled; } static void Make(){ return new Order(); } void Order(){ Status=Status.Pending; } }
I personally do not like the use of "statuses", they automatically apply to everything that uses them - I see that there is an unnecessary connection .
So I would have something like this:
class Order{ void CancelOrder(){ IsCanceled=true; } void FillOrder(){ if(IsCanceled) throw Exception(); IsFilled=true; } static Order Make(){ return new Order(); } void Order(){ IsPending=true; } }
It is best to use so-called domain events to change related things when changing order status.
My code will look like this:
class Order{ void CancelOrder(){ IsCanceled=true; Raise(new Canceled(this)); }
If the order is too large, you can check that the contexts are limited (as Eric Evans says - if he had the chance to write his book again, he would move the restricted context to the very beginning).
In short, this is a domain-driven decomposition form.
The idea is relatively simple - itโs quite normal to have several Orders from different points of view, for example, contexts.
eg. - Order from the purchase context, Order from the accounting context.
namespace Shopping{ class Order{
But usually enough of the domain itself avoids complexity and is easily decomposable if you listen to it close enough. For instance. You can hear from experts such terms as OrderLifeCycle, OrderHistory, OrderDescription, which you can use as anchors for decomposition.
NB: Keep in mind - I got a zero idea of โโyour domain.
It is very likely that these verbs that I use are completely strange to him.