MATLAB Object-Oriented Programming

(Joyce) #1

gobj.AxesHandle = get(h,'Parent');
end


Implement the zoom Method


The LineGraph zoom method follows the comments in the GraphInterface class which
suggest using the camzoom function. camzoom provides a convenient interface to
zooming and operates correctly with the push buttons created by the addButtons
method.


Define the Property Set Methods


Property set methods provide a convenient way to execute code automatically when the
value of a property changes for the first time in a constructor. (See “Property Set
Methods” on page 8-56.) The linegraph class uses set methods to update the line
primitive data (which causes a redraw of the plot) whenever a property value changes.
The use of property set methods provides a way to update the data plot quickly without
requiring a call to the draw method. The draw method updates the plot by resetting all
values to match the current property values.


Three properties use set methods: LineColor, LineType, and Data. LineColor and
LineType are properties added by the LineGraph class and are specific to the line
primitive used by this class. Other subclasses can define different properties unique to
their specialization (for example, FaceColor).


The GraphInterface class implements the Data property set method. However, the
GraphInterface class requires each subclass to define a method called updateGraph,
which handles the update of plot data for the specific drawing primitive used.


The LineGraph Class


Here is the LineGraph class definition.


classdef LineGraph < graphics.GraphInterface
properties
LineColor = [0 0 0]
LineType = '-'
end


methods
function gobj = LineGraph(data,varargin)
if nargin > 0
gobj.Data = data;


Define an Interface Superclass
Free download pdf