MATLAB Object-Oriented Programming

(Joyce) #1
This subsref enables the use of dot notation to create a plot using the name 'plot'.
The statement:

obj = MyPlot(1:10,1:10);
h = obj.plot;

calls the plot function and returns the handle to the graphics object.

You do not need to code each method and property name. The otherwise code in the
inner switch block manages any name reference that you do not explicitly specify in
case statements. However, using this technique exposes any private and protected class
members via dot notation. For example, you can reference the private property, x, with
this statement:

obj.x

ans =

1 2 3 4 5 6 7 8 9 10

The same issue applies to writing a subsasgn method that enables assignment to private
or protected properties. Your subsref and subsasgn methods might need to code each
specific property and method name explicitly to avoid violating the class design.

See Also


Related Examples



  • “Code Patterns for subsref and subsasgn Methods” on page 17-21

  • “Indexed Reference” on page 17-28

  • “Indexed Assignment” on page 17-31


17 Specialize Object Behavior

Free download pdf