MATLAB Object-Oriented Programming

(Joyce) #1
end
end

When you create a PropertyGroup object using a cell array of property names, MATLAB
automatically


  • Adds the property values for a scalar object display

  • Uses the property names without values for a nonscalar object display (including
    empty object arrays)


The getPropertyGroups method is not called to create the display for a scalar handle
to a deleted object.

Change the Values Displayed for Properties


Given the same class properties used in the previous section, you can change the value
displayed for properties by building the property list as a struct and specifying values
for property names. This override of the getPropertyGroups method uses the default
property display for nonscalar objects by calling the superclass getPropertyGroups
method. For scalar objects, the override:


  • Changes the value displayed for the Password property to a '*' character for each
    character in the password.

  • Displays the text 'Not Available' for the Salary property.
    methods (Access = protected)
    function propgrp = getPropertyGroups(obj)
    if ~isscalar(obj)
    propgrp = [email protected](obj);
    else
    pd(1:length(obj.Password)) = '*';
    propList = struct('Department',obj.Department,...
    'JobTitle',obj.JobTitle,...
    'Name',obj.Name,...
    'Salary','Not available',...
    'Password',pd);
    propgrp = matlab.mixin.util.PropertyGroup(propList);
    end
    end
    end


The object display looks like this:

EmployeeInfo with properties:

Department: 'Product Development'

18 Customizing Object Display

Free download pdf