Methods in Class Design - MATLAB & Simulink (original) (raw)

Main Content

Class Methods

Methods are functions that implement the operations performed on objects of a class. Methods, along with other class members support the concept of encapsulation—class instances contain data in properties and class methods operate on that data. This design allows the internal workings of classes to be hidden from code outside of the class, and thereby enabling the class implementation to change without affecting code that is external to the class.

Methods have access to private members of their class including other methods and properties. This encapsulation enables you to hide data and create special interfaces that must be used to access the data stored in objects.

Examples and Syntax

For an example to get started writing classes, see Creating a Simple Class.

For sample code and syntax, see Method Syntax.

For a discussion of how to create classes that modify standard MATLAB® behavior, see Methods That Modify Default Behavior.

For information on the use of @ and path directors and namespaces to organize your class files, see Class File Organization.

For the syntax to use when defining classes in more than one file, see Methods in Separate Files.

Kinds of Methods

There are specialized kinds of methods that perform certain functions or behave in particular ways:

Method Naming

The name of a function that implements a method can contain dots (for example, set.PropertyName) only if the method is one of the following:

You cannot define property access or conversion methods as local functions, nested functions, or separately in their own files. Class constructors and namespace-scoped functions must use the unqualified name in the function definition; do not include the namespace name in the function definition statement.

See Also

Topics