MATLAB Object-Oriented Programming

(Joyce) #1

Customize Display for Heterogeneous Arrays


You can call only sealed methods on nonscalar heterogeneous arrays. If you want to
customize classes that are part of a heterogeneous hierarchy, you must override and
declare as Sealed all the methods that are part of the CustomDisplay interface.

The versions of disp and display that are inherited from
matlab.mixin.CustomDisplay are sealed. However, these methods call all of the part
builder (“Part Builder Methods” on page 18-4) and state handler methods (“State Handler
Methods” on page 18-5).

To use the CustomDisplay interface, the root class of the heterogeneous hierarchy can
declare these methods as Sealed and Access = protected.

If you do not need to override a particular method, then call the superclass method, as
shown in the following code.

For example, the following code shows modifications to the getPropertyGroups and
displayScalarObject methods, while using the superclass implementation of all
others.
classdef RootClass < matlab.mixin.CustomDisplay & matlab.mixin.Heterogeneous
%...
methods (Sealed, Access = protected)
function header = getHeader(obj)
header = [email protected](obj);
end
function groups = getPropertyGroups(obj)
% Override of this method
% ...
end
function footer = getFooter(obj)
footer = [email protected](obj);
end
function displayNonScalarObject(obj)
[email protected](obj);
end
function displayScalarObject(obj)
% Override of this method
% ...
end
function displayEmptyObject(obj)
[email protected](obj);
end

18 Customizing Object Display

Free download pdf