22.4. Revising Adding a Post

Adding a post is currently accomplished with the following classes:

  • AddPostEvent

  • AddPostDelegate

  • AddPostCommand

  • LoadCategoriesEvent

  • LoadCategoriesCommand

  • LoadCategoriesDelegate

The AddPostEvent will become a type of the new PostEvent class.

The addPost function of the AddPostDelegate will move to the new PostDelegate class.

The AddPostCommand will be updated to cast the event as a PostEvent and use the new PostDelegate.

The LoadCategoriesEvent will become a type of the CategoryEvent class.

The loadCategories function of the LoadCategoriesDelegate will be moved to the CategoryDelegate class.

The execute function of the LoadCategoriesCommand will be updated to use the CategoryDelegate.

Start with the new event class for posts. In the com.FlexBlog.events package create a new event class named PostEvent. Edit the class to match the following:

package com.FlexBlog.events
{
    import com.FlexBlog.valueobjects.PostVO;
    import com.adobe.cairngorm.control.CairngormEvent;
    public class PostEvent extends CairngormEvent
    {
        public static const ADD:String = 'addPostEvent';
        public var post:PostVO;
        public function PostEvent(type:String, post:PostVO = null,
        bubbles:Boolean=false, cancelable:Boolean=false)
        {
            super(type, bubbles, cancelable);
            this.post =post;
        }
    }
}

Now create the new post delegate class. In the com.FlexBlog.delegates package create a new delegate class named PostDelegate. Edit the class to match the following:

package com.FlexBlog.delegates { import com.FlexBlog.valueobjects.PostVO; ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.