Difference between revisions of "Classdef"

From Octave
Jump to navigation Jump to search
(function handles in OOP context)
m (use direct url instead of archived docs)
Line 22: Line 22:
* [http://www.mathworks.com/help/releases/R2015a/matlab/matlab_oop/mutable-and-immutable-properties.html Immutable property] set access. Example:
* [http://www.mathworks.com/help/matlab/matlab_oop/mutable-and-immutable-properties.html Immutable property] set access. Example:
<source lang="octave">
<source lang="octave">
classdef MyClass < handle
classdef MyClass < handle

Revision as of 01:27, 19 June 2015

This page is a stub. We should begin documenting what classdef is implemented and what is not.

not supported

  • enumeration
  • build-in class as superclass
    • classdef nonsense < uint32
  • array of objects. Example:
classdef MyClass < handle

c = MyClass();
cc = [c, c];   % won't work

For now you can use a cell-array of objects instead:

cc = {c, c};   % ok
classdef MyClass < handle
    properties (SetAccess = immutable)
        function obj = MyClass()
            x = rand();

Use "private" properties as workaround.

  • Function handles to package methods and static class methods.

For example if we have +mypackage/myfunc.m, creating a function handle as fh = @mypackage.myfunc won't work. As a workaround, we can create an indirection using an anonymous function fh = @(varargin) mypackage.myfunc(varargin{:}). Similarly for static class methods where fh = @MyClass.myfunc isn't yet supported.


  • methods
    • static
    • private

Classdef examples in the wild