Q:

Overloading Octave Functions

I am relatively new to Octave and just getting started with classes.  I have a class with a constructor in the following form:
classdef MyClass < handle
properties
  property1
  property2
endproperties
methods
  function self = MyClass(Param1) % Constructor
    self.property1 = Param1;
    self.property2 = "SOMEVALUE"
  endfunction
endmethods
endclassdef

Now I would like to accommodate other parameters by overloading the constructor so I tried using the following form:
classdef MyClass < handle  
properties
  property1
  property2
endproperties
methods
  function self = MyClass(Param1) % Constructor
    self = self.MyClass(Param1, "SOMEVALUE")
  endfunction

  function self = MyClass(Param1, Param2) % Constructor
    self.property1 = Param1;
    self.property2 = Param2;
  endfunction
endmethods
endclassdef

Using this format, I receive an error:
error: 'Param2' undefined near line x column y

I am not sure how to proceed.  The Octave documentation has one vague example and virtually no explanation as to how to overload functions.
Obviously I am working with the wrong paradigm in mind.  Any suggestions or good resources would be greatly appreciated. :)

A:

Use Argument Checking Functions
Explanation
To create the effect of overloaded functions you have to explicitly check the number and type of arguments and react programmatically on the number and type of arguments. There is no direct way of overloading class members in octave (yet). In your example you would use the octave implementation of a default argument.
Simple Solution
This very simple solution does only check for the number of arguments and does set the second argument to a default value if it is not present.
classdef myClass < handle  

  properties
    property1
    property2
  endproperties

  methods
    function self = myClass(Param1, Param2) % Constructor
      if nargin < 2
        Param2 = "SOMEVALUE";
      endif
      self.property1 = Param1;
      self.property2 = Param2;
    endfunction
  endmethods

endclassdef

Example Output
>> a=myClass(1)
a =

<object myClass>

>> a.property1
ans =  1
>> a.property2
ans = SOMEVALUE

More Complex Solution
For more complex overloading I recommend using a variable length argument list with varargin in combination with an inputParser object.
Avoid overloading
Because of the minimal support octave provides for function overloading I recommend to avoid overloading as far as possible.

