Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: How to summarize Matlab's OOP features?

Subject: How to summarize Matlab's OOP features?

From: Dimitri Shvorob

Date: 2 Dec, 2007 10:31:34

Message: 1 of 2

Hi,

I have been looking at OOP facilities of Matlab, and wrote
up an ultra- brief bullet-point summary, to jog my memory
if/when I get around to using them. Would anyone counsel
corrections or additions?

Thank you.



a) 'dedicated' class folder

b) absence of a header/prototype file listing class members
(constructor lists only class properties, not other methods)

c) classes as property-containing structures, converted
with 'class()'

d) 'segregation' of class methods into separate m-files

e) optional 'display' and 'char' methods

f) any derived-class object contains the 'enveloped' base-
class object as its explicit member

g) an (at-least-) two-step way of modifying an object by
its method: a property change, then an "eval('base',.."-
like "assignin('caller',.." 'commit'

h) class properties: always private

i) class methods: public, unless respective m-files are
placed in 'private' sub-directory

j) inheritance: always private (hence, methods of a derived
class can access inherited base-class properties of a
derived-class object only through base-class accessors)

k) no derived-to-base casts

l) no pure virtual methods (hence, no abstract classes)

m) [See (f)] a two-step way of invoking a virtual base-
class method (vs. the derived-class 'override' namesake).
For example, to get the balance of a savings account, with
SavingsAccount derived from BankAccount and getBalance
implemented in BankAccount, need:

parent = sa.BankAccount;
ans = getBalance(parent);

n) [Combination of (g) and (m)]. a four-step (!) way of
modifying inherited properties of a derived-class object.
For the example above, with balance a property of
BankAccount class, adjustable through its setBalance
method, need

parent = sa.BankAccount;
setBalance(parent,100)
sa.BankAccount = parent;
assignin('caller',inputname(1),sa)

Going back to (g), if balance belonged to SavingsAccount,
two steps would suffice:

sa.balance = 100;
assignin('caller',inputname(1),sa)

o) no static classes

Subject: How to summarize Matlab's OOP features?

From: Dimitri Shvorob

Date: 2 Dec, 2007 11:17:15

Message: 2 of 2

.. I think I would stick another bullet point between (d)
and (e):

'Within m-file' overloading: for example, default
constructor, 'regular' constructor and copy constructor are
placed in a single m-file, and choice between the three
made by testing inputs

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
class object oop Dimitri Shvorob 2 Dec, 2007 05:35:01
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics