help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: override display() for class


From: CdeMills
Subject: Re: override display() for class
Date: Fri, 10 Dec 2010 01:18:38 -0800 (PST)

display receives as input the VALUE of an object, it is up to this function
to suitably produce a text with the fields of the object. To determine the
NAME of the argument passed to the function, use the "inputname" function?
So your overloaded function should be

function text = display(myclass)

text = sprintf('%s value is %d', inputname(1), myclass.val)

endfunction

Now, overloading means having the ability to mimic some fundamental
function, applied to a class you did define. In the name of the "least
surprise effect", you should try to stay as close as possible to the
fundamental function behaviour.

Regards

Pascal
-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/override-display-for-class-tp3081116p3081620.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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