Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map EditModel to Command Messages?

Jimmy Bogard at Los Techies says that he maps his EditModel to Command Messages instead of mapping EditModel to DomainModel. Can anyone explain this further?

like image 554
Carl Hörberg Avatar asked Dec 11 '25 12:12

Carl Hörberg


1 Answers

I'd guess it'd be a version of the command pattern that performs the necessary manipulations on the relevant domain objects based on the supplied message. e.g. Something like

public PromoteEmployeeCommand : ICommand {
     private readonly PromotionMessage _message;
     private readonly IEmployeeRepository _repository;

     public PromoteEmployeeCommand(PromotionMessage message,
                                   IEmployeeRepository repository) {
          _message = message;
          _repository = repository;
     }

     public void Execute() {
          /* Get the employee, give them a rise etc... */
     }
}

The mapping from the edit model would resolve to a number of command messages that could be invoked as required (e.g. Give employee a rise, notify their manager, add a note for payroll etc).

The advantage of this approach is that it can isolate your domain model from any presentational concerns exposed by the Edit model.

like image 163
John Foster Avatar answered Dec 13 '25 14:12

John Foster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!