Category Archives: Java

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.