Leveraging factory pattern for UI components in Flex


Using Factory method for UI components is always a good Idea. This helps adding common look/feel, validation etc. to a set of similar component at centralized place.
For example:

  • Text box for price input with custom requirement (as only two decimal places, in a given range, a custom look and feel etc.) can appear on multiple pages
  • Standard stuff as email entry boxes can have similar custom requirement

There are two approaches to deal with above

  1. One argument that most of validation is standard and out of box these day (Email, Date) while css and styling can be leveraged from a shared location, so these can be done “in place”. But greatest flip side I see that any change, say decimal precision from 2 places to 3, color change, background image change etc., will have to be tracked at multiple pages, even if just a reference change (CSS name, Validator name etc).
  2. Factory approach -I can have a method as
    UIElement getATextBoxWith2PlaceDecimal(){
    }
    

    This can encapsulate all validation and custom requirements.

I tend to use factory If I see repeatation on lot of pages -it seems to be a cleaner and maintainable approach.

About these ads

About ChandanPandey

Try to come up with a good design as by product of good coding practices

Posted on June 14, 2011, in Design and Architecture, Flex, Java and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: