MATLAB Object-Oriented Programming

(Joyce) #1
Emp123 =

handle to deleted EmployeeInfo

Implementation

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


  • getHeader

  • getPropertyGroups

  • getFooter


Each method must produce the desired results with each of the following inputs:


  • Scalar object

  • Nonscalar object array

  • Empty object array


getHeader Method Override


MATLAB calls getHeader to get the header text. The EmployeeInfo class overrides this
method to implement the custom header for scalar display. Here is how it works:


  • Nonscalar (including empty object) arrays call the superclass getHeader, which
    returns the default header.

  • Scalar handles to deleted objects do not result in a call to getHeader.

  • Scalar inputs build a custom header using the getClassNameForHeader static
    method to return linked class name text, and the value of the Department property.


Here is the EmployeeInfo override of the getHeader method. The required protected
access is inherited from the superclass.
methods (Access = protected)
function header = getHeader(obj)
if ~isscalar(obj)
header = [email protected](obj);
else
className = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
newHeader = [className,' Dept: ',obj.Department];
header = sprintf('%s\n',newHeader);
end

18 Customizing Object Display

Free download pdf