!
©!2009!DevelopmentArc!LLC,!All!rights!reserved.!
Overall,!the!Construction!Phase!is!really!just!prepping!the!component!to!be!used!and!
very!little!of!the!instance!is!configured!or!available!during!this!time.!!We!recommend!
that!you!perform!as!little!work!or!calculations!as!possible!during!this!time,!and!try!
to!move!setup!code!to!later!phases!of!the!component.!
Using+Initialization+
Similar!to!Construction,!the!Initialize!Phase!is!one!of!the!most!overused!and!
probably!abused!phases!by!Flex!developers.!!For!us!(the!authors),!one!of!the!most!
eye!opening!experiences!of!researching!this!paper!was!the!realization!of!our!
improper!use!of!the!initialize()!method.!!To!be!perfectly!honest,!as!developers,!
we!were!notorious!for!using!the!initialize()!method!as!a!place!to!do!a!lot!of!
configuration!and!setup,!especially!when!using!the!Code!Behind!Pattern
33
.!
The!reason!we!adopted!initialize()!as!the!desired!override!for!setting!properties!
is!that!this!was!the!first!apparent!location!that!the!children!have!been!created!
(meaning!they!are!available!to!us),!the!styles!can!be!set/accessed!and!most!of!the!
component!is!ready!to!be!used.!!For!many!of!us,!finding!the!best!location!to!perform!
these!kinds!of!setup!was!the!first!real!grey!area!of!the!Flex!documentation.!
To!determine!the!best!location!for!this!kind!of!configuration,!we!had!to!find!it!
through!experimentation!and!a!bit!of!on‐the‐fly!research.!!Through!this,!we!
discovered!the!Initialization!Phase,!which!at!the!time!felt!like!a!logical!place!to!do!
this!kind!of!setup.!!Once!found,!we!stopped!digging!deeper!because!it!got!the!job!
done.!Unfortunately,!this!solution!didn’t!always!work.!!In!most!cases,!it!was!safe!for!
what!we!were!building!but!every!once!and!a!while!a!strange!race!condition!would!
appear,!or!some!issue!would!appear!that!could!only!be!teased!out!during!integration!
testing.!
Now!that!we!have!fully!researched!the!Flex!Lifecycle,!our!general!recommendation!
is!that!you!don’t!override!initialize()!at!all.!!If!you!look!at!most!of!the!Flex!UI!
components,!they!never!override!the!initialize() method,!and!for!good!reason.!!
The!problem!with!initialize() is!that!when!you!inject!code!via!override!you!may!
very!well!be!in!the!middle!of!a!implementation!hierarchy!and!what!you!expect!to!be!
configured!may!not!be!ready!just!yet.!
The!Flex!component!architecture!has!split!the!Initialize!phase!into!multiple!sub‐
steps!and!there!are!better!methods!available!for!us!to!override.!!The!best!one!to!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33
#The#Cod e#Behind#Pattern#(CBN) #is#a#Flex#design#pattern #that #enables#to#developers#to#separate#layo ut#
from#logic#by#crea ting# a#“backin g”#ActionScript#Cla ss#that#the#MXML#layout#extends# from.##This#enables#
developers#to#keep #layout#so lely#in#MXML#and#a ll#programmatic#logic#in#the#ActionScript#Class.##The #CBN#
is#one#of#the#more#divisive#Flex#patterns#in#the# community.##For#ev ery#pro^CBN#developer#th ere#is#an#anti^
CBN#develope r.##At#DevelopmentArc,#we#are#strong#proponen ts#for#using#th e#pattern#and# have#found#it#
beneficial#to#the#growt h#and#maintenance#of#applications.##For#more#information#about#the#CBN,#we#
recommend#reading#Ja mes’#write#up#at#hi s#blog#Viv isecting#Media .#
!
http://blog.vivisec tingmedia.com/2008/04/the^flex^code^behind^pattern/#
#
Kommentare zu diesen Handbüchern