Christian
Christian

Reputation: 1291

Are there advanced uses for Grails command objects?

Are there advanced uses for Grails command objects? Majority of the pages out there have a command object with all of its fields as Strings, Floats, Integers. Is there a way to make it use domain classes similar to how a Domain class may have have a reference to another domain class.

Upvotes: 1

Views: 403

Answers (2)

Igor
Igor

Reputation: 33963

Yes, this is completely legal, and I use them this way in projects all the time. Their purpose is to validate input, and the main difference between a domain object and a command object is that the command object is not persisted.

Most of the sites probably do not use other Objects in order to make the example a bit simpler to understand.

Upvotes: 1

aldrin
aldrin

Reputation: 4572

I don't see why not. Sure they can hold instances to other domain classes. Typically command objects are used when you only need a subset of the properties of your domain class or when there is no corresponding domain class.

Upvotes: 1

Related Questions