help-octave
[Top][All Lists]
Advanced

[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 14:01:59 -0800 (PST)

Judd Storrs-2 wrote
> 
> On Thu, Feb 9, 2012 at 3:45 PM, CdeMills <Pascal.Dupuis@> wrote:
>>
>> 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.
> 
> I think maybe I wasn't clear. I was wondering if there's a way to
> avoid creating:
> 
> @wrapper/sin.m
> @wrapper/cos.m
> @wrapper/permute.m
> @wrapper/fft.m
> @wrapper/ifft.m
> @wrapper/abs.m
> @wrapper/arg.m
> @wrapper/imshow.m
> @wrapper/imwrite.m
> .
> .
> .
> 
> which is quite tedious because the only thing that varies is the
> method name. So, I was wondering if there was a way to define a
> wildcard method that would be called if no methods were defined.
> The interpreter is going to toss an error and stop anyway.
> 
> Writing wrapper methods is just to prototype and simulate what it
> would be like to use a subclass of a builtin type. Directly
> subclassing the builtin would be preferable--it would avoid
> interpreter overhead during dispatch.
> 
> 

Judd,

you were quite clear. In the implementation of dataframe, I have all those
methods, just differing by the function handle they pass to the private
function in charge of dispatching the call to the right place.

I understand the concept of wildcard method, but what would be "subclassing
a builtin" ?

Regards

Pascal

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Some-OOP-questions-tp4373321p4374554.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]