views:

28

answers:

2

Very often I face the same problem with Flex: When I create a skin for spark component or create new spark component based on another spark component I have inherited properties that I don't need. For example, when I create a custom skin for spark.components.Panel I don't need RectangularDropShadow. At the moment to get rid of it I remove it from MXML code and create a public variable in AS of the same type named as it was in removed component id. I do this to satisfy Liskov principle for OOP and it works (http://en.wikipedia.org/wiki/Liskov_substitution_principle) but I have unused properties/variables which is not nice. I don't think that this is the best way it could be done.

Of course there is another approach: In order to create custom panel without unneeded inherited features spark.components.Panel I have to create my own custom panel inherited from super class of spark.components.Panel for example. This approach implies some extra work work, but this is straight forward OOP approach.

But maybe there are other Flex specific techniques which I don't know yet?

I would like to know how Flex-gurus handle this issue. All you ideas and suggestions are Welcome!

+1  A: 

Well if this is specific to skinning Flex components, you can easily not use the RectangularDropShadow class by instead extending ProgrammaticSkin or your own ProgrammaticSkin class that implementes the IProgrammaticSkins methods.

Quote:

Of course there is another approach: In order to create custom panel without unneeded inherited features spark.components.Panel I have to create my own custom panel inherited from super class of spark.components.Panel for example.

As for this, I think you are worrying about it too much. Do whatever makes you most comfortable of course, but one of Flex's architectural design constraints is to allow developers to rapidly develop RIAs without having to worry about pesky little things like memory management. However, kudos to you for worrying about unneeded features and wasted resources, but I don't think it is necessary because it would be a waste of time to create your own Panel class every single time you needed a slightly different feature set. But hey, it's like my Ma always said, "Free memory is wasted memory!"

Jonathan Dumaine
+1  A: 

I'm not sure if this is what you're looking for, but you can use the Exclude metadata to tell code hinting to ignore style or property.

It is not uncommon in the Flex Framework to find code that excludes a property and then overrides the getter and setter to do nothing. This in the metadata:

[Exclude(name="label", kind="property")] 

And this as the code:

override public get function label():String{return null}
override public set function label(value:String):void { }

You can remove styles using:

[Exclude(name="RectangularDropShadow", kind="style")] 

Of course, this just affects code hinting. The code to implement the style will most likely still be in your component.

What you're talking about is just the nature of inheritance. Why is it important for you to remove these styles / properties from the code?

www.Flextras.com
I just wanted to post the same answer (I came to it yesterday). If I overwrite functions like you have shown - then there is no need in unused property. Thank you!
MinimeDJ