[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Object based octave instead of Object Oriented Octave...
From: |
James Moliere |
Subject: |
Object based octave instead of Object Oriented Octave... |
Date: |
Sat, 11 Apr 2009 21:56:29 -0700 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090320) |
Hello,
I'm trying to learn Octave's new 'Object Oriented Programming'. I must
say, I didn't see anywhere in the documentation the concepts of
inheritance so I recommend that the phrase 'Object Based Programming' be
used. Please correct me if I'm wrong.
I also played with a counter class that simply increments when the inc()
method is called.
octave:1> a=counter(1)
octave:2> b=counter(5)
octave:3> c=counter(2, a)
octave:4> c=inc(c)
with the error
error: class has no member `other'
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error: /home/jmoliere/octave/@counter/inc.m at line 8, column 8
error: /home/jmoliere/octave/@counter/inc.m at line 8, column 8
How do I formerly create class members? ...I couldn't find the phrase
'class member' in the Octave documentation version 3.1.52+.
Thanks!
James Moliere
#this is bad code below but it's just for learning the new features in
Octave.
@counter/counter.m
------------------------------------------------------------
function cntr = counter(a, other)
if (nargin == 0)
cntr.counter = 0;
cntr.other = [];
cntr = class (cntr, "counter");
elseif (nargin == 1)
if (strcmp (class(a), "counter"))
cntr = a;
cntr.other = [];
elseif (isvector (a) && isreal(a))
cntr.counter = a(1);
cntr = class(cntr, "counter");
else
error("counter: expected another counter or a starting value");
endif
elseif (nargin == 2)
if (strcmp (class(a), "counter"))
cntr = a;
cntr.other = other;
elseif (isvector (a) && isreal(a))
cntr.counter = a(1);
cntr.other = other;
cntr = class(cntr, "counter");
else
error("counter: expected another counter or a starting value");
endif
endif
endfunction
-------------------------------------------------------
file: @counter/inc.m
--------------------------------------------------------
# throw away code just to try to understand the new features in Octave.
function c = inc(a)
a.counter = a.counter+1;
disp(a.counter);
#a.other.counter = a.other.counter+1;
#disp(a.other.counter);
if (strcmp(class(a.other), "counter"))
a.other=inc(a.other);
endif
c = a;
endfunction
--------------------------------------------------------
- Object based octave instead of Object Oriented Octave...,
James Moliere <=