I see your point; that inheritance can be considered evil in some situations. In this case though, I think that it's ok; since a MatRix is an Array; or in this case an ArrayCollection. However, I do agree that you can just as easily create a stand-alone MatRix class as well. Like you say, it depends on the use-case.
-TH --- In flexcoders@yahoogroups.com, Richard Rodseth <rrods...@...> wrote: > > Limited time, and not sure what the original goal is. But if the poster > needs a Matrix class he can make one that doesn't derive from anything, or > that implements an interface. In fact, if you look at flash.geom.Matrix > you'll see it derives from Object. > > Googling "composition vs inheritance" or "delegation vs inheritance" should > yield lots of guidance on the general principle. > > HTH > > On Tue, Apr 28, 2009 at 3:39 PM, Tim Hoff timh...@... wrote: > > > > > > > > > Care to elaborate with an example? > > > > -TH > > > > > > --- In flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>, Richard > > Rodseth rrodseth@ wrote: > > > > > > I wouldn't extend either of these. Favour delegation over inheritance. > > > > > > On Tue, Apr 28, 2009 at 3:23 PM, Tim Hoff TimHoff@ wrote: > > > > > > > > > > > > > > > Yep, thought that I could get away with not testing it. Doesn't look > > like > > > > you can extend Array, but you can extend ArrayCollection: > > > > > > > > *package > > > > *{ > > > > * import* mx.collections.ArrayCollection; > > > > * > > > > public* *class* MatRix *extends* ArrayCollection > > > > { > > > > * public* *function* MatRix(numRows:int=0,numCols:int=0) > > > > { > > > > * for* (*var* i:int=0;i<numRows;i++) > > > > { > > > > * this*.addItem( *new* Array(numCols) ); > > > > } > > > > } > > > > } > > > > } > > > > > > > > Test: > > > > > > > > *var* a:MatRix = *new* MatRix(3,3); > > > > a[0][1] = *"test"*; > > > > *trace*(a[0][1]); > > > > > > > > -TH > > > > > > > > --- In flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>, > > "smitade" smitade@ wrote: > > > > > > > > > > This compiles OK but fails at this point in the class: > > > > > > > > > > this[i]=new Array(numCols); > > > > > > > > > > with the error: Cannot create property 0 on [the class] i.e i > > being 0 on > > > > the first for loop when calling: > > > > > > > > > > var a:MatRix = new MatRix(3,3); > > > > > > > > > > > > > > > > > > > > > > >