"Steven_Lord" <firstname.lastname@example.org> wrote in message <email@example.com>... > > > "Eric Sampson" <ericDOTsampson@gmail.com> wrote in message > news:firstname.lastname@example.org... > > I posted the below on Answers but got no responses, perhaps the newsgroup > > is a better forum to discuss this :) > > --------- > > > > So I can't really recall ever creating a value class, all mine seem to be > > handle classes. Is that the same as your experience? Unless I'm completely > > missing something, using value classes seems to be a bit ungainly, because > > you always have to do two steps like this: > > > > foo = MyValueClass(5); % sets a property 'val' > > foo = foo.double(); > > plot(foo.val); > > Why does the DOUBLE method of the MyValueClass return an object instead of a > double array? >
Sorry Steve, my example was quickly made and obviously confusing; I was intending the DOUBLE method to just take the current value of the VAL property and multiply it by two, not do a conversion. I didn't even realize that DOUBLE/CHAR/etc methods had special meanings, I should have called my method TIMESTWO to prevent confusion :)
properties val = ; end
methods function obj = timestwo(obj, in) obj.val = 2 * in; end end
Perhaps the above might explain my original question better now? I can't return the result of TIMESTWO directly instead of the object, because if I did that then the modified object (containing the updated VAL) would not overwrite the original object in the base workspace. I could change the timestwo method to look like this, function [obj, out] = timestwo(in), but then I couldn't call it in a chained function call situation like plot(sin(obj.timestwo(5))) ...
Thanks Steve, I'll confess that I hadn't figured out the purpose of that abstract class yet! I think the fact that it was in the 'mixin' package threw me off, compared to the other abstract handle classes like hgsetget/dynamicprops which are not - I guess I figured from that fact & the package name that it had to do with defining a mixin class.