2 Jun 2008 12:18
Re: [groovy-dev] Regd DGM
My Accounts class may be several things. It will mostly likely have some notion of how to step through its accounts but I am not sure there is much benefit in forcing it to implement java.util.Iterator. Groovy lets me adopt interface oriented programming if I choose but also has the hooks for duck typing too. Paul. Saager Mhatre wrote: > wait, but wouldn't your Customer.accounts be some form of Collection? > GPath expressions could also be coercable to Collections. Then we're > golden without having to pollute Object. > > On Mon, Jun 2, 2008 at 1:04 PM, Paul King <paulk@... > <mailto:paulk@...>> wrote: > > Saager Mhatre wrote: > > I know what Duck typing is, and don't particularly like it. > Besides, I don't think we should have duck typing over a Class > based OO platform; creates room for too much confusion. > > I just felt like it was polluting the interface of java.lang.Object. > > > The current solution while not perfect provides some nice convenience > once you become familiar with it. If in my Customer class I have a > reference to an Accounts class then I can say: > > customer.accounts.findAll{ a -> a.balance > 0 } > > rather than forcing Accounts to implement java.util.Iterator or > using the more cumbersome: > > customer.accounts.iterator().findAll{ a -> a.balance > 0 } > > For this simple case it might not appear to make much difference > but the subtle difference is the basis of what makes GPath work > as nicely as it does. > > Paul. > > > IMHO, if you're calling an internal iterator method (each, find, > any, all, ...) on a non-iterable, the system shoudl just give > you a sensible exception instead of defaulting to returning the > object itself. The current approach seems to have the potential > to mask possible errors. > > On Sun, Jun 1, 2008 at 5:00 AM, Martin C. Martin > <martin@... <mailto:martin@...> > <mailto:martin@... > <mailto:martin@...>>> wrote: > > > > Saager Mhatre schrieb: > > Then why not just add them into java.util.Iterator > and array > variants? Why java.lang.Object? Isn't that a smell? > Aren't > we polluting the interface of java.lang.Object? > > I know that's a lotta questions, but it's late and my > head's > spinning! :S > > > It's duck typing: > > http://en.wikipedia.org/wiki/Duck_typing > > Best, > Martin > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > > > -- > Saager Mhatre > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > > > -- > Saager Mhatre --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
RSS Feed