OOP load update

Judd Storrs storrsjm at email.uc.edu
Tue May 5 22:44:13 CDT 2009


I'm pretty sure the constructor is called if Matlab doesn't have a class
definition. Suppose:

@FooBar/FooBar.m:
function obj = FooBar()
     disp('Hello!');
     obj.data = 'Baz';
     obj = class(obj, 'FooBar');

Then at least in Matlab R14 (7.0.1) (I've edited whitespace):

Matlab Session 1:
>> obj1 = FooBar()
Hello!
obj1 = FooBar object: 1-by-1
>> save('test.mat','obj1')
>> obj2 = FooBar()
Hello!
obj2 = FooBar object: 1-by-1
>> save('test2.mat','obj2')
>> exit

Matlab Session 2:
>> load test.mat
Hello!
>> load test2.mat
>>

As you see in the second session, matlab does execute the constructor the
first time it encounters the FooBar class, but once it knews the class
structure, it didn't need to call the constructor again.

--judd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/octave-maintainers/attachments/20090505/2a728858/attachment.html 


More information about the Octave-maintainers mailing list