MATLAB Documentation for OOP
(For reference by students)


 

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.
set/get methods to access each data item [actually, for child classes, but a good general principle]
 

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
 
 


Got comments\feedback\suggestions\complaints\anything whatsoever? Shoot the webmaster an email!

Website created & maintained by Shardul Bhatia and Wen Eu Cheah