MATLAB Object-Oriented Programming

(Joyce) #1

  • It is a handle class (it derives from handle).

  • All its superclasses are handle compatible (handle classes are handle compatible by
    definition).


classdef HPropertyDefaults < handle & Utility
properties
GraphPrim = line
Width = 1.5
Color = 'black'
end
end

The HPropertyDefaults class is handle compatible:

hpd = HPropertyDefaults;
mc = metaclass(hpd);
mc.HandleCompatible

ans =

1

Nonhandle Subclasses of a Handle-Compatible Class

If you subclass both a value class that is not handle compatible and a handle compatible
class, the subclass is a nonhandle compatible value class. The ValueSub class:


  • Is a value class (it does not derive from handle.)

  • One of its superclasses is handle compatible (the Utility class).


classdef ValueSub < MException & Utility
methods
function obj = ValueSub(str1,str2)
obj = obj@MException(str1,str2);
end
end
end

The ValueSub class is a nonhandle-compatible value class because the MException
class does not define the HandleCompatible attribute as true:

hv = ValueSub('MATLAB:narginchk:notEnoughInputs',...
'Not enough input arguments.');
mc = metaclass(hv);
mc.HandleCompatible

12 How to Build on Other Classes

Free download pdf