34.6.2 Properties

All class properties must be defined within properties blocks. The definition of a default value for a property is optional and can be omitted. The default initial value for each class property is [].

A properties block can have additional attributes to specify access rights or to define constants:

classdef some_class
  properties (Access = mode)
    prop1
  endproperties

  properties (SetAccess = mode, GetAccess = mode)
    prop2
  endproperties

  properties (Constant = true)
    prop3 = pi ()
  endproperties

  properties
    prop4 = 1337
  endproperties
endclassdef

where mode can be one of:

public

The properties can be accessed from everywhere.

private

The properties can only be accessed from class methods. Subclasses of that class cannot access them.

protected

The properties can only be accessed from class methods and from subclasses of that class.

When creating an object of some_class, prop1 has the default value [] and reading from and writing to prop1 is defined by a single mode. For prop2 the read and write access can be set differently. Finally, prop3 is a constant property which can only be initialized once within the properties block.

By default, in the example prop4, properties are not constant and have public read and write access.

: properties (class_name)
: properties (obj)
: plist = properties (…)

Return or display the public properties for the named class class_name or classdef object obj.

If an output value is requested, return the list of property names in a cell array.

Programming Note: Property names are returned if the GetAccess attribute is public and if the Hidden attribute is false.

See also: methods.

© 1996–2020 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/v6.3.0/Properties.html