Question about OOP basics

Hello again, friends. Thanks for indulging all my beginner questions!

I’m trying to get my hands dirty with classes. From what I’ve read, classdef classes are not currently implemented in a usable way (e.g. Classdef - Octave), so I’m starting out with old-style classes instead. (Please correct me if I’m mistaken… I’d love to use classdef classes, but it just sounds like that would be a frustrating and futile exercise?)

I’m using Octave 6.3.0 GUI on Windows.

Here’s my first question: is there a way to get Octave to see new methods immediately when I create them? Or, if that’s not possible, how can I ask Octave to rescan the load path? With non-class functions and scripts, I find that Octave seems to be automatically scanning my load path all the time, so that if I create a new function it becomes usable immediately, but this doesn’t seem to be the case for methods of classes.

I am putting my class source code in A:\Documents\octave\classes, which is in my load path. The methods that existed when I invoked Octave are visible, but any new ones that I’ve created since starting my session don’t get loaded. I’ve tried adding A:\Documents\octave\classes\@classname to the path, in which case it does immediately see the new methods, but this causes all sorts of other problems because it perceives them to be stand-alone functions rather than class methods.

Thanks again, and again I’m sorry for asking such basic questions.

Solomon

I was working through a similar classdef adventure as you. Currently you need to refresh class changes by issuing a

clear -c

My understanding is that classdef has improved quite a bit over time since the wiki was first created, but it’s not perfect. I decided to take the plunge anyway and hope I wouldn’t run into an incompatibility/unimplemented roadblock. I figured running into them is the only way to generate the bugs that might eventually get fixed :slight_smile:
(E.g, see
Classdef inconsistent testing errors? )

Thanks, I’ll try clear -c.

It was specifically your thread Classdef inconsistent testing errors? which convinced me that it was not time to try using classdef… are you having any success?

In general, https://wiki.octave.org/Classdef gave me the idea that one can’t have arrays of classdef objects, and in my case if I can’t have arrays of objects then there’s no point. Has that been fixed at all? Or have I misunderstood the issue?

I don’t know your exact usage, but you can have multiple objects within a container object such as a cell array. Here is sample code using the built-in containers.Map classdef object.

obj1 = containers.Map ();
obj2 = containers.Map ();
all_objs = {obj1, obj2};

Ah, hmm. Well, it sounds like you’re recommending classdef classes. And to be honest, if they do work, they would make my life a lot easier (for example it seems that old-style objects are all immutable, meaning, no handle objects, which means that they can’t retain state in between method calls unless they return a copy of themselves which the calling function has to deal with?)

I’ll give classdef a try.

Thank you, and thank goodness for this community! <3