They seem to wrap around domain classes ...
You can use command objects in this way, but this is not their main use.
Command objects are useful when you want to encapsulate a group of query parameters and do something together with them. This may or may not have anything to do with domain classes.
For example, you might have a Grails application that doesn't have any domain classes at all, and command objects can be really useful. Imagine a Grails application, which is just a service layer that receives a request from web forms or REST requests using the JSON body or something else, and the Grails application will receive these requests, check the input, maybe do some math or anything at all, and then make a REST call to another process that can store them in a database or generate reports or something else. In this situation, there are many reasons why you can use command objects, even if none of the domain classes are involved.
Do not get confused when thinking that team objects must be bound to domain classes. Sometimes they are, but do not limit your thinking of them in this context. Use command objects if you want to link a group of query parameters together and do something with them.
source share