From: "Dan Stevens (IAmAI)" Date: 2007-07-06T08:04:29+09:00 Subject: Re: Calling an arbitrary method as and when an array's contents change > 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? Truth is, I've now realised that I actually don't *need* an answer to this question to solve my problem (helps to have full insight into one's problems first). However, for the sake of argument and my curiosity, does anyone thing there's an easier and more reliable solution? On 05/07/07, MenTaLguY wrote: > On Fri, 6 Jul 2007 07:13:31 +0900, "Dan Stevens (IAmAI)" wrote: > > I have a collection class that extends the Array class and I wish to > > have a particular method to be called whenever the contents of an > > instance of the class change. Can anyone advise on how I can achieve > > this? > > For this purpose, it's probably better to wrap/delegate to Array than extend it. > > That way, you can have control of all the methods that change something, and > guarantee that they will perform the appropriate notification. I'd also > recommend looking at Observer for the notification of the equation. > > -mental > > >