MATLAB Object-Oriented Programming

(Joyce) #1

methods (Abstract)
abstMethod(obj)
end


For methods that declare the Abstract method attribute:



  • Do not use a function...end block to define an abstract method, use only the
    method signature.

  • Abstract methods have no implementation in the abstract class.

  • Concrete subclasses are not required to support the same number of input and output
    arguments and do not need to use the same argument names. However, subclasses
    generally use the same signature when implementing their version of the method.


Abstract Properties


Define an abstract property:


properties (Abstract)
AbsProp
end


For properties that declare the Abstract property attribute:



  • Concrete subclasses must redefine abstract properties without the Abstract
    attribute.

  • Concrete subclasses must use the same values for the SetAccess and GetAccess
    attributes as those attributes used in the abstract superclass.

  • Abstract properties cannot define access methods and cannot specify initial values.
    The subclass that defines the concrete property can create access methods and specify
    initial values.


For more information on access methods, see “Property Access Methods” on page 8-50.


Determine If a Class Is Abstract


Determine if a class is abstract by querying the Abstract property of its meta.class
object. For example, the AbsClass defines two abstract methods:


classdef AbsClass
methods(Abstract)
result = absMethodOne(obj)


Abstract Classes
Free download pdf