OOP/Class Questions: deepcopy & AbortSet

조회 수: 1 (최근 30일)
Peter Cook
Peter Cook 2018년 4월 3일
답변: Guillaume 2018년 4월 3일
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