| CS 1371 Dept. Presents: |
| CLASS | |
|---|---|
| Definition | This is the set of plans from which an object can be constructed. A class is
the program that describes how to build an object, what kinds of data it will
contain, and what kinds of things can be done to and with this data. The
following methods are required for all classes to be stored in its main
directory: The Constructor – a method named the same as the class that consumes
initialization data and produces the initial data structure display.m – the method called whenever Matlab wants to display the contents
of an object char.m – a method returning a character string describing this object Any other methods required to manipulate the data for this object are also
stored here. |
| Example |
function
acct = BankAccount(data) ---> Name of the class (matches the file
and directory name)
if nargin == 0
acct.balance = 0;
acct = class(acct,'BankAccount');
elseif
isa(data,
'BankAccount')
acct = data;
else
acct.balance = data;
acct = class(acct,'BankAccount');
end
|