Matlab R2012a を使用すると、次のクラス階層があります。
classdef Parent < handle
properties (Abstract, SetAccess = protected)
Limit
end
end
classdef SimpleChild < Parent
properties (SetAccess = protected)
Limit = 1.0
end
end
classdef ExtendedChild < Parent
properties (Access = private)
Child = SimpleChild
end
properties (Dependent, SetAccess = protected)
Limit
end
methods
function this = ExtendedChild
this.Limit = 2;
end
function output = get.Limit(this)
output = this.Child.Limit;
end
function set.Limit(this,input)
this.Child.Limit = input;
end
end
end
これは、"Parent" クラスが "SimpleChild" クラスと "ExtendedChild" クラスの両方で実装される抽象 "Limit" プロパティを定義する簡単な例です。「ExtendedChild」クラスは、「SimpleChild」クラスのプライベート インスタンスをカプセル化し、アクセス メソッド (get/set) をプライベート インスタンスに転送します。「ExtendedChild」インスタンスの構築が失敗し、次のメッセージが表示されます。
>> obj = ExtendedChild
Setting the 'Limit' property of the 'SimpleChild' class is not allowed.
Error in ExtendedChild/set.Limit (line 16)
this.Child.Limit = input;
Error in ExtendedChild (line 10)
this.Limit = 2;
「制限」プロパティは、保護された SetAccess を使用して「親」クラスで定義されているため、設定可能であると予想していました。プロパティを「Parent」クラスに直接実装すれば問題は解消できますが、構築(インターフェースと実装の分離)のポイントである「ExtendedChild」クラスに依存として再定義することはできません。
私が何か間違ったことをしているかどうか誰かに教えてもらえますか?