How are method names with a dot in them accessed in classes?

In the tutorial Implementing a Set/Get Interface for Properties, a class MyAccount is implemented as a subclass of HGSETGET with part of the SET method overloaded. This is done by adding a method set.AccountStatus. However, this method does not show up in the list of methods for MyAccount. Moreover, there does not seem to be any way of calling this method. For example, the following command sequence gets a mysterious error:
>> h = MyAccount(1234567,500,'open');
>> h.set.AccountStatus('frozen')
??? Index exceeds matrix dimensions.
Moreover, if SET is overloaded, this method has no effect on the behavior of MyAccount.
EDIT: An attempt to access set.AccountStatus within SET has strange effects. If this code is inserted in the class,
function obj = set(obj,varargin)
obj = obj.set.AccountStatus(varargin{2});
end
and
>> h.set.AccountStatus('frozen')
is run, then obj.set.AccountStatus(varargin{2}) actually calls set(obj,{}).
How are methods with dots in their names accessed? EDIT: Is it still possible to access methods like SET.ACCOUNTSTATUS if I modify SET?

 採用された回答

Daniel Shub
Daniel Shub 2011 年 8 月 23 日

0 投票

While this answer is very late and I think you have found a work around for HGsetgetplus ...
Under "Defining Access Methods" you can get a function handle to the set.AccountStatus method via the metaclass
m = ?myClass; m.Properties{1}.Name m.Properties{1}.SetMethod

1 件のコメント

Andrew Newell
Andrew Newell 2011 年 8 月 25 日
Thank you, Daniel. I read this documentation page multiple times, and somehow never noticed that the answer was there.

サインインしてコメントする。

その他の回答 (1 件)

David Young
David Young 2011 年 2 月 25 日

2 投票

For normal classes, the set/get methods are called automatically when you assign to or access a property:
h.AccountStatus = 'frozen';
calls the set.AccountStatus method.
If you inherit from hgsetget, then you should be able to do
set(h, 'AccountStatus', 'frozen');
to call set.AccountStatus instead.

2 件のコメント

Jiro Doke
Jiro Doke 2011 年 2 月 25 日
To add to David's answer, set/get methods are the only ones that are implemented with a dot in the method. When you set the value of the property or get the value, the appropriate set/get method gets called. No other methods can have a dot in the name.
Andrew Newell
Andrew Newell 2011 年 2 月 26 日
Thank you both - you answered the question I asked, but it wasn't really the question I needed to ask. I have edited the question to get to the nub of it. See also http://www.mathworks.com/matlabcentral/answers/1998-implementing-an-hgsetget-subclass for why I am asking this.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by