0 Replies Latest reply on Jan 26, 2011 2:27 PM by WhatDoesThatDo

    Should Value Objects Extend SkinnableComponent?


      If you have a value object called Product.as, received from a server lets say via AMFPHP should this VO extend SkinnableComponent so you display it directly? What are the advantages and disadvantages?


      Here is a very simple example of Product.as Class:


      public class Product
              public var id:Number;
              public var name:String;
              public var brand:String;
              public var price:Number;
              public var description:String;
              public var inStock:Boolean;
              public var imageURL:String;
              public function Product()


      Now It would be useful if this VO extended SkinnableComponent you could create a skins to show the product information in different ways e.g. just a price tag (showing price), a product thumbnail (showing image, name, brand) or show all the products details.


      So you would end up with ProductPriceTagSkin.mxml, ProductThumbnailSkin.mxml, ProductDetailsSkin.mxml + the Product.as - this is all well and good, isn't it?


      Well what happens if you want to use the price tag on its own, without the Product class? Ah problem - because its just a skin its tied to the HostComponent Product class.


      OK so lets take another route, the Product class does not inherit from SkinnableComponent instead lets say it inherits from EventDispatcher.


      So now we have to create separate components/classes for each "view" and a skin for each of these. e.g. What was the ProductThumbnailSkin.mxml now becomes ProductThumbnailSkin.mxml but this has a HostComponent of ProductThumbnail.as which has the properties of; imageURL, name, brand and extends SkinnableComponent.


      OK so we can now pass the properties from the Product.as to the ProductThumbnail.as which has a skin of ProductThumbnailSkin.mxml. As the ProductThumbnail.as is not tied to Product.as you can use it in other projects or on its own without a Product.


      Now this all seems great but you have to create extra files bit annoying but you gain flexibility for your pains. Now the above example, I think seems fairly doable but what happens when we come to do the ProductDetail.as and ProductDetailsSkin.mxml. ProductDetails.as is going to have the exact same properties as Product.as so now we have come full circle why not just make Product.as extend SkinnableComponent and have 3 skins ProductPriceTagSkin.mxml, ProductThumbnailSkin.mxml, ProductDetailsSkin.mxml? But now we are back at the catch of loosing flexibility and re-use.


      I keep flitting back and forth between which method would be the best set-up to allow flexibility and maintainability, what is everybody else's thoughts? Are the different methods? I hope my twittering's make sense?