Suppressing superclass methods/events

16 ビュー (過去 30 日間)
Daniel Dolan
Daniel Dolan 2011 年 12 月 9 日
編集済み: Hamid Ramezani 2021 年 6 月 7 日
Is there a way to suppress super class methods and events? For example, a class based on handle:
classdef my_class < handle
inherits methods (addlistener, isvalid, etc.) that users of my_class don't need. I want to preserve a clean interface that prevents access to things defined outside of my_class.
  2 件のコメント
Walter Roberson
Walter Roberson 2011 年 12 月 9 日
Would it be enough to hide them somehow, so they don't show up in a normal methods listing? Or do they have to be gone?
Daniel Dolan
Daniel Dolan 2011 年 12 月 16 日
Hiding would be sufficient. I want to build classes based on handle, preserving the set/get capabilities of hgsetget, but I don't want the end user to see other methods defined by the superclass (eq, ge, gt, and so on).

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

採用された回答

Hamid Ramezani
Hamid Ramezani 2019 年 9 月 16 日
編集済み: Hamid Ramezani 2021 年 6 月 7 日
This is the best you can do to hide the methods which are relared to handle (here superclass). All te methods are hidden except 'isvalid' which is a sealed method of 'handle' class.
classdef myClass < handle
methods
function O = myClass()
end
end
methods (Hidden)
function varargout = findobj(O,varargin)
varargout = findobj@handle(O,varargin{:});
end
function varargout = findprop(O,varargin)
varargout = findprop@handle(O,varargin{:});
end
function varargout = addlistener(O,varargin)
varargout = addlistener@handle(O,varargin{:});
end
function varargout = notify(O,varargin)
varargout = notify@handle(O,varargin{:});
end
function varargout = listener(O,varargin)
varargout = listener@handle(O,varargin{:});
end
function varargout = delete(O,varargin)
varargout = delete@handle(O,varargin{:});
end
end
end

その他の回答 (1 件)

Daniel Shub
Daniel Shub 2011 年 12 月 10 日
I don't think so. I think this would violate the idea that an object of a subclass is also an object of the superclass. Maybe you do not want to subclass the handle class, this will reduce the number of inherited methods.
You also could switch to the old OOP system where you had to roll your own methods for nearly everything and hence had more control.
It is unclear why isvalid, and the like, would give individuals access to things outside your class.
You also could overload subsref to prevent calls to addlistener and isvalid. This could get ugly though.

カテゴリ

Help Center および File ExchangeMethods についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by