OOP/Class Questions: deepcopy & AbortSet

2 次查看(过去 30 天)
1. What is the correct way to deepcopy an instance of a class/object whose superclass is type `handle`? `copyobj` doesn't seem to work for a handle-derived class that isn't strictly a graphics object, and overloading `copyobj` as a class method to copy each field into a new instance and return a handle seems to take just as long as constructing a new object.
2. Does it make sense to specify `AbortSet` for a `Dependent` class property? Yes, I understand you can't `set` a `Dependent` property but I have defined an overloaded `set` method to access a private class property that can be set. Does it make most sense to only specify `AbortSet` for the private class property it accesses? i.e.
properties(Dependent, AbortSet)
...
%display settings
filterTimeBand
...
end
properties(Access = private, AbortSet)
...
privateFilterTimeBand = 30;
...
end
...
function propval = get.filterTimeBand(hObj)
%return the number of points used in the 2D DTS filter time
%band (x-direction / columns)
propval = hObj.privateFilterTimeBand;
end
function set.filterTimeBand(hObj,nCol)
%update the number of points used in the 2D DTS filter time
%band (x-direction / columns)
if isnumeric(nCol) && nCol>0
%first update the filter time band
hObj.privateFilterTimeBand = ceil(nCol);
%next re-filter temperature using the new filter window
hObj.filterDtsData;
end
end

采纳的回答

Guillaume
Guillaume 2018-4-3
1. Deriving from matlab.mixin.copyable is the easiest. It's a bit of work to implement but it provides a well defined interface.
2. AbortSet on a dependent property is pointless since it'll never have a PreSet or PostSet event nor will it ever be set. I would assume that matlab just ignore the attribute for dependent properties but just in case, I would not include it.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by