O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

19.2. Value Objects

Since comments are associated with particular posts, you will be using the postId property of a post to load the associated comments. Which comments are displayed is determined by the currently selected post: therefore you can use the postId property of the PostVO referenced by the currentPosts property of the ModelLocator to load the associated comments.

When submitting a comment you still need the postId, but you also need the body of the comment and the id of the user making the posts. So once again a comment can be seen as a collection of related data that needs to be passed around as a unit. Because of this you will create a value object to represent comments.

The query, or the act of retrieving comments, returns the following columns:

  • commentId

  • postId

  • userId

  • body

  • madeOn

  • postedBy

These include all the columns from the comments table and the name of the person who made the comment contained in the postedBy property retrieved via a join in the SQL.

In the com.FlexBlog.valueobjects package create a new value object class named CommentVO. Edit the class to match the following:

package com.FlexBlog.valueobjects
{
    public class CommentVO
    {
        public var commentId:int
        public var postId:int
        public var userId:int;
        public var body:String;
        public var madeOn:String;
        public var postedBy:String;
    }
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required