From: dblack@... Date: 2002-12-14T23:09:24+09:00 Subject: Re: Is it wise to extend Matrix? Hi -- On Sat, 14 Dec 2002, Gavin Sinclair wrote: > Since the thread "Inheritance question" has become so deep (physically :) and > my point is sort of orthoganal to it, new thread. > > I personally don't believe it makes sense to create a class that inherits from > Matrix. Doing so would suggest to me that you are creating a new kind of > Matrix. If you are, then perhaps you should visit a local mathematician to see > whether there really is more than one kind of Matrix. Same goes for Array and > probably some others. I've always had a fondness for inheriting from Array and Hash... though, you point out in your example, it can be overkill, leaving an object with methods that really have nothing to do with it. But sometimes the fit is rather good -- those core classes are core for good reasons. I've never thought of it in terms of claiming that there's a new kind of Array or Hash; I see it more as just incrementally building on the available components of the language. > In Jim's case, he wanted to add some methods to Matrix. Well, he didn't want > to change Matrix directly, but the methods he was going to add would in no way > be out of place in the real Matrix class, so to me, inheritance is the wrong > approach. Delegation is the key here. Create a new class based on Matrix, add > your methods, and forget that Matrix ever existed. I spot an opportunity to learn more about delegation, something which I've never really absorbed. Can you elaborate a bit on the conditions under which delegating would be a better choice than inheriting in this example? David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav