[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Some OOP questions
From: |
CdeMills |
Subject: |
Re: Some OOP questions |
Date: |
Thu, 9 Feb 2012 12:45:21 -0800 (PST) |
Judd Storrs-2 wrote
>
>
> @wrapper/foo.m:
> function w = foo(w, varargin)
> w.data = foo(w.data, varargin{:});
> endfunction
>
> Is there a different way to handle that? Maybe something like a
> generic "missing method" handler for the class?
>
>
In the case of dataframes, I solved the problem like this
@wrapper/foo.m:
function resu = foo(A, B, varargin)
try
resu = wrapper_func(@plus, A, B, varargin{:});
catch
disp(lasterr());
error("Operator foo problem for %s vs. %s", class(A), class(B));
end_try_catch
end
@wrapper/private/wrapper_func
function resu = wrapper_func(func, A, B, varargin{:})
if (isa(A, 'wrapper'))
if isa(B, 'wrapper'))
resu = feval(func, A.data, B.data, varargin{:});
else
resu = feval(func, A. data, B, varargin{:});
and so on. This way, only private/wrapper_func has to care if arguments are
or not of class wrapper. All overloaded functions only differ in the name
they're transmitting to wrapper_func. Some genericity should be good, but
it's doable without it.
Regards
Pascal
--
View this message in context:
http://octave.1599824.n4.nabble.com/Some-OOP-questions-tp4373321p4374312.html
Sent from the Octave - General mailing list archive at Nabble.com.