From: Gregory Brown Date: 2007-07-06T08:26:22+09:00 Subject: Re: Calling an arbitrary method as and when an array's contents change On 7/5/07, Dan Stevens (IAmAI) wrote: > > Ah! I'd forgotten about the observer pattern. That should do the trick. Thanks! > > After looking at the Observable module, it only really solves half of > my problem. While it's a nice mechanism for notify observers that an > object has changed, it does help me determine whether or not an object > has changed; it leaves that up to the programmer. > > > For this purpose, it's probably better to wrap/delegate to Array than extend it. > > This is a potential solution - I could override all the methods of the > Array class that I think modify the contents of the Array in a > superclass, calling Observable#changed before/after calling the > parent's method. However, what if I think there's one too many methods > to be overriding or a forget to override one? Um.... do you really need an observable array or are you building an object that uses an array under the hood that needs to be observable? Big difference there. In the former case, you'll likely want to use a blank slate proxy that does the notification on delegation. On the latter case it's really easy, just notify on the methods you're actually using. :) Word on the street is that subclassing core classes to change behaviour is a bad idea anyway. You might risk your subclass methods not getting called in favor of the C methods being called without you knowing...