2 Replies Latest reply on Sep 22, 2010 12:40 PM by Flex harUI

    Why use value objects?

    TransoniqHacker

      I am trying to delve a little deeper into Flex and have come across discussions about using value objects. My question is why would you use them?

      I have an application that stores records in a database using ColdFusion as a backend. Currently I use an HTTPService to call a coldfusion page that returns XML that gets put in a XMLListCollection. This is then used to populate a datagrid and form details when the datagrid item is clicked on. This all works fine and is very easy (if not very elegant, it was one of my first applications)

       

      I have another that uses a remote object to a coldfusion cfc. This cfc returns a query based on verious parameters. This result is then put in an ArrayCollection and used various ways.

       

      What is wrong with doing things this way and why/how would value objects help?

       

      Thanks.

      Matt

        • 1. Re: Why use value objects?
          dmclean62md

          Your example has nothing to do with value objects.

           

          Value objects are useful in a number of situations such as:

           

          1. They can efficiently represent a limited number of values. Say you have a size field with only four possible values: small, medium, large and extra large. You can use value objects and store the ordinal value (1 to 4) in a single byte instead of needing an 11 byte string. The set of value objects can be used as a white list for validating or constraining user input.

           

          2. You can attach other information to a value object (within reason). Say your app allows users to select from a list of colors. You can store the RGB color information in the value object for each color.

           

          There are probably other uses such as with strategy patterns (http://en.wikipedia.org/wiki/Strategy_pattern) as well.

          • 2. Re: Why use value objects?
            Flex harUI Adobe Employee

            If you define ValueObject as a strongly-typed data class, then the

            advantages are that the compiler will find typos, the time to read and write

            properties from the objects is an order of magnitude faster, the time

            required to convert XML to valueObjects goes away and the total number of

            bytes over the network should be less.