MATLAB Object-Oriented Programming

(Joyce) #1

Personal Info
Salary: 'Level: 10'
Password: '***'


Implementation


The EmployeeInfo class overrides two matlab.mixin.CustomDisplay methods to
implement the display shown:



  • displayScalarObject — Called to display valid scalar objects

  • getPropertyGroups — Builds the property groups for display


displayScalarObject Method Override


MATLAB calls displayScalarObject to display scalar objects. The EmployeeInfo
class overrides this method to implement the scalar display. Once overridden, this method
must control all aspects of scalar object display, including creating the header, property
groups, and footer, if used.


This implementation:



  • Builds a custom header using the getClassNameForHeader static method to return
    linked class name text and the value of the Department property to get the
    department name.

  • Uses sprintf to add a new line to the header text

  • Displays the header with the built-in disp function.

  • Calls the getPropertyGroups override to define the property groups (see following
    section).

  • Displays the property groups using the displayPropertyGroups static method.


Here is the EmployeeInfo override of the displayScalarObject method. The
required protected access is inherited from the superclass.


methods (Access = protected)
function displayScalarObject(obj)
className = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
scalarHeader = [className,' Dept: ',obj.Department];
header = sprintf('%s\n',scalarHeader);
disp(header)
propgroup = getPropertyGroups(obj);
matlab.mixin.CustomDisplay.displayPropertyGroups(obj,propgroup)


Customize Display of Scalar Objects
Free download pdf