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

17.2. Value Objects

You will need value objects to represent posts and post categories.

Starting with the post value object, the FlexBlogDatabaseManager uses a view in the database to retrieve posts. A view is just a collection of data from several tables that you can query without having to write the SQL to get the data from each table. This view contains all the columns found in the posts table, with some additional columns for retrieving such things as the author's name. Since the post value object will be used to both transfer data and display posts in the application, you will model it after the view. This will give you all the properties needed to both transfer data and display all the information returned from the post view.

The posts view in the database has the following columns:

  • postId

  • authorId

  • categoryId

  • title

  • body

  • createdOn

  • authorName

  • categoryName

In the com.FlexBlog.valueobjects package, create a new class named PostVO. Edit the class to match the following:

package com.FlexBlog.valueobjects
{
    public class PostVO
    {
        public var postId:int;
        public var authorId:int;
        public var categoryId:int;
        public var title:String;
        public var body:String;
        public var createdOn:String;
        public var authorName:String;
        public var categoryName:String;
    }
}

Post categories are stored in the categories table of the database. This table consists of two columns:

  • categoryId

  • name

In the selection mechanism used by the author, you want to display the textual representation of the category found in the name ...

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