MATLAB Object-Oriented Programming

(Joyce) #1
Scalar handles to deleted objects do not result in a call to getFooter.

methods (Access = protected)
function footer = getFooter(obj)
if isscalar(obj)
footer = sprintf('%s\n','Company Private');
else
footer = '';
end
end
end

Complete Class Listing
classdef EmployeeInfo < handle & matlab.mixin.CustomDisplay
properties
Name
JobTitle
Department
Salary
Password
end
methods
function obj = EmployeeInfo
obj.Name = input('Name: ');
obj.JobTitle = input('Job Title: ');
obj.Department = input('Department: ');
obj.Salary = input('Salary: ');
obj.Password = input('Password: ');
end
end
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
end
function propgrp = getPropertyGroups(obj)
if ~isscalar(obj)
propList = {'Department','Name','JobTitle'};
propgrp = matlab.mixin.util.PropertyGroup(propList);
else
gTitle1 = 'Public Info';
gTitle2 = 'Personal Info';
propList1 = {'Name','JobTitle'};
propList2 = {'Salary','Password'};
propgrp(1) = matlab.mixin.util.PropertyGroup(propList1,gTitle1);

18 Customizing Object Display

Free download pdf