checkMethodsInClassdef
Check if all methods that are declared in a classdef file are also implemented, that the declaration is the same as the implementation (i.e. do not declare varargin but have a method with (x,y,x) input arguments). Check that all methods that have an implementation in a separate file are also declared.
Abstract methods
Abstract methods cannot be implemented in the class itself, but instead must be implemented in each subclass. Please note that abstract classes can have non-abstract methods:
classdef (Abstract) Example
% This class is abstract and cannot be instantiated directly. This does not
% require the subclass to implement anything.
methods
% These methods are *not* abstract and need an implementation in this
% class. The implementation can be provided in a function block right
% here. When only a declaration is provided, the method must be
% implemented in the class @-folder.
%
% Subclasses *may* override this method, but it is not mandatory.
function x = create(obj)
x = obj.x;
end
end
end
classdef Example
methods (Abstract)
% These methods are abstract (and therefore also the class) and are not
% allowed to have an implementation in this class. Subclasses cannot be
% instantiated unless they implement all methods.
%
% A function body here is an error:
% Illegal value for attribute 'Abstract' in class 'Example'. In the
% 'Example' class, the 'create' method has both the Abstract
% attribute and a function body.
%
% An implementation in the class @-folder will give a warning followed
% by an error when creating an instance of the Subclass:
% Warning: In the 'Example' class, the 'create' method has both the
% Abstract attribute and a function body.
%
% Error: Abstract classes cannot be instantiated. Class 'Subclass'
% inherits abstract methods or properties but does not implement
% them. See the list of methods and properties that 'Subclass' must
% implement if you do not intend the class to be abstract.
x = create(obj)
end
end
Configurable parameters
-
AllowDifferentInputOutputNames (boolean): Set to true to have CC4M allow for differences in method input and output names between method declaration and implementation. By default, this parameter is set to
false
. -
AllowVararginout (boolean): Set to true to have CC4M allow the use of varargin/varargout in method input and output declaration and implementation.
Exemption tag: %@ok<MDAMI>