Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.mixin.Heterogeneous.getDefaultScalarElement

Class: matlab.mixin.Heterogeneous
Package: matlab.mixin

Return default object for heterogeneous array operations

Syntax

defaultObject = getDefaultScalarElement

Description

defaultObject = getDefaultScalarElement returns the default object for a heterogeneous hierarchy. Override this method if the root class is abstract or is not an appropriate default object for the classes in the heterogeneous hierarchy. getDefaultScalarElement must return an instance of another member of the heterogeneous hierarchy.

The implementation of getDefaultScalarElement inherited from the matlab.mixin.Heterogeneous class returns an instance of the root class. If the root class is abstract, you must implement getDefaultScalarElement in the root class to return a default object. For more information, see Root Class.

MATLAB® calls the getDefaultScalarElement method when requiring a default object. For more information on heterogeneous arrays and default objects, see matlab.mixin.Heterogeneous.

Output Arguments

defaultObject

The default object for heterogeneous array operations.

Attributes

Statictrue
AccessProtected
Sealedtrue not required

To learn about attributes of methods, see Method Attributes in the MATLAB Object-Oriented Programming documentation.

Examples

This example describes a heterogeneous hierarchy with a root class (FinancialObjects) that is an abstract class and cannot, therefore, be used for the default object. The FinancialObjects class definition includes an override of the getDefaultScalarElement method which returns an instance of the Assets class as the default object.

The root class can override the getDefaultScalarElement method that is defined in matlab.mixin.Heterogeneous class and return an Assets object as the default object.

classdef FinancialObjects < matlab.mixin.Heterogeneous
   methods (Abstract)
      val = determineCurrentValue(obj)
   end
   methods (Static, Sealed, Access = protected)
      function default_object = getDefaultScalarElement
         default_object = Assets;
      end
   end
end

Definitions

expand all

Tips

  • Override getDefaultScalarElement only if the root class is not suitable as a default object.

  • Override getDefaultScalarElement only in the root class of the heterogeneous hierarchy.

  • getDefaultScalarElement must return a scalar object.

  • getDefaultScalarElement must be a static method with protected access. While not required by MATLAB, you can seal this method to prevent overriding by other classes.

  • MATLAB returns an error if the value returned by getDefaultScalarElement is not scalar or is not an instance of a class that is a valid member of the hierarchy.

Was this topic helpful?