Command pattern :- A request is wrapped under an object as command and passed to invoker object. Invoker object looks for the appropriate object which can handle this command and passes the command to the corresponding object which executes the command.
Consider a Employee management system where HR person can create/read/update/delete employee. In my career I have always designed this use case something like
Request from browser -> EmployeeController -> EmployeeService -> EmployeeDao
EmployeeService.java will contain all create/read/update/delete operations which will be called from controller
After reading Command pattern , I see another way of doing it where controller will work as Invoker to call appropriate CommandHandler like DeleteCommandHandler/UpdateCommandHandler/CreateCommandHandler/ViewCommandHandler
Is applying Command design pattern makes sense here ?
Aucun commentaire:
Enregistrer un commentaire