Thanks guys, the inverted idiom is indeed easier I'll try that
Yang On Tue, May 31, 2011 at 1:36 PM, Doug Cutting <[email protected]> wrote: > You might invert the encapsulation, so that each Fruit instance contains > a 'flavor' field that's a union of types like Apple and Orange? > > Doug > > On 05/31/2011 08:33 PM, Yang wrote: > > I understand that avro does not have inheritance now, so I am wondering > > what is the best way to achieve the following goal: > > > > I define Apple, Orange, and Fruit. Apple and Orange should ideally > > derive from Fruit, but since there is no built-in mechanism, > > we create an internal member for aboth Apple and Orange, encapsulating > > the contents of Orangle > > > > Apple :{ > > Fruit: fruit_member > > > > string: pattern_on_skin > > } > > > > Orange : { > > > > Fruit: fruit_member > > > > string: skin_thickness > > } > > > > > > Fruit: { > > int : size, > > string: color > > int: weight > > } > > > > > > > > say I want to pass objects of both Apple and Orange to some scale to > > measure the total weight, > > I can pass them just as Objects, > > > > > > int findTotalWeight(List<Object> l ) { > > > > int result=0; > > for(Object o : l ) { > > result += ??????? <============ somehow get access to the > > fruit_member var ?? > > } > > } > > > > > > so what is the best way to fill in the line above with "<====" ? doing a > > lot of instanceof is kind of cumbersome > > > > > > Thanks > > Yang > > >
