help-octave
[Top][All Lists]
Advanced

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

RE: override display() for class


From: Steve White
Subject: RE: override display() for class
Date: Wed, 15 Dec 2010 20:45:19 +0100

Hi,
Here's my solution, as it stands.

The problem is, how to properly override the output functions to 
properly display the contents of class objects, and to emulate the
behavior of echoing assignment of a class object to a variable.

I know of three built-in output functions
    display()
    disp()
    fdisp()
Given what OO progamming is supposed to be, it would be 
a pity to override all of those in each derived class.

Ideally, the core text formatting should be done just once
per subclass, and all the rest handled by inheritance.
It appears that fdisp and disp do not call one another
(perhaps they call some common function: if I could
override that, this could be easier). 

Anyway, I choose to make disp and display call fdisp.  
This way, in derived classes, one only needs to override

    fdisp()

The base class overrides look like this:
==============================================

function fdisp (fh, q)
        # ... class internals formatting.  Note the newline is required.
                fprintf (fh, " formatting\n", q.contents);
endfunction
==============================================

function disp (q)
        fdisp (stdout, q);
endfunction
==============================================
function display (q)
        fprintf (stdout, "%s =", inputname (1))
        fdisp (stdout, q);
endfunction
==============================================


Cheers!
                                          


reply via email to

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