What exactly are Handle Compatible Classes? Are they a combination of handle and non-handle classes?
7 次查看(过去 30 天)
显示 更早的评论
I read Handle Compatible Classes, the page say"Typically, when deriving a MATLAB® class from other classes, all the superclasses are handle classes, or none of them are handle classes. However, there are situations in which a class provides some utility that is used by both handle and nonhandle subclasses. Because it is not legal to combine handle and nonhandle classes, the author of the utility class must implement two distinct versions of the utility.
The solution is to use handle-compatible classes. You can use handle-compatible classes with handle classes when forming sets of superclasses. Designate a class as handle compatible by using the HandleCompatible class attribute."
I know “The HandleCompatible attribute is not inherited.”
I ran the following code,I found that the objects defined by A do not belong to any class! Why is this happening?
ta=A;
ty=isa(ta,'handle')
ty=isa(ta,'value')
ty=isa(ta,'HandleCompatible')
I ran the following code,tb do not belong to any class either! Why?
tb=B;
ty=isa(tb,'handle')
ty=isa(tb,'value')
ty=isa(tb,'HandleCompatible')
I ran the following code.Why can't I define objects for class C? I don't quite understand this error message.
c=C;
Error using C
If a class defines super-classes, all or none must be handle classes.
I have defined three classes, and the code is as follows:
classdef (HandleCompatible=true) A
properties
a
end
end
classdef B < A
properties
b
end
end
classdef C < B & handle
properties
c
end
end
0 个评论
采纳的回答
Matt J
2023-8-28
编辑:Matt J
2023-8-28
I found that the objects defined by A do not belong to any class! Why is this happening?
The syntax of of isa() is,
isa(object,classname)
but 'value' and "HandleCompatible' are not the names of classes. You cannot query whether an object is a value or handle compatible class this way.
Why can't I define objects for class C?
The handle compatibility of A is not inherited by B, see Handle Compatibility Rules
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Handle Classes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!