Effacer les filtres
Effacer les filtres

OOP/Class Questions: deepcopy & AbortSet

3 vues (au cours des 30 derniers jours)
Peter Cook
Peter Cook le 3 Avr 2018
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

Réponse acceptée

Guillaume
Guillaume le 3 Avr 2018
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.

Plus de réponses (0)

Catégories

En savoir plus sur Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by