Value Objects

We will now add a value object called TimecardVO to the model. This will be the value object for the Timecard entity and we will keep it simple by mapping it one-to-one with the Timecard entity. The model for the TimecardVO looks like this:

Value Object Diagram

The TimeTracker front end will receive TimecardVO objects from the time tracking service. Typically items that the front end will need to display are put in value objects. For example we could add a string with the submitting user's name toTimecardVO, even though this information may or may not be stored in the actual Timecard entity.

  1. Create a new diagram by right clicking on the VO package and clicking New Diagram |Class Diagram. Set the name of the diagram to Value Object Diagram and clickOk.
  2. Click the Class tool Class Tool in the toolbar and make a new class on the surface. Double click on the class, name itTimecardVO, and add the Value Object stereotype to it.
  3. Right click on the TimecardVO object and selectInsert new attribute. Add three public attributes to the class by:
    • One called id of typeLong.
    • One called startDate of typeDate.
    • One called comments of typeString.
  4. Drag the Timecard class onto the diagram. Click the Dependency tool Dependency Tool and draw a dependency from the Timecard class to the TimecardVO class. Adding this dependency will tell AndroMDA that the Timecard entity will be converted to TimecardVO objects, and it will generate helper code in the generated TimecardDao data access class to support translation between them.
  5. Click the Class tool Class Tool in the toolbar and make a new class on the surface. Double click on the class and name itTimecardVO[]. We do not need to add a stereotype to it. This will create a type that we can use to return collections of TimecardVO objects from service methods.