Saving all Superclass properties inside one subclass property

1 回表示 (過去 30 日間)
Ravindra
Ravindra 2020 年 8 月 5 日
コメント済み: Ravindra 2020 年 8 月 5 日
Feature class created with proerties featid & to_delete
classdef Feature < handle
properties (Access = public)
% Unique ID of this feature
featid;
% If this feature should be deleted
to_delete;
end
methods
function obj = Feature()
end
function obj=clean_old_measurements(obj,valid_times)
end
end
end
Sub class FeatureDatabase inherites from Feature class
classdef FeatureDatabase < Feature
properties (Access = public)
% Mtx for our map
mtx;
% Our lookup array that allow use to query based on ID
features_idlookup;
end
methods
function obj = FeatureDatabase()
% Default constructor
obj.features_idlookup = Feature;
end
function obj=cleanup_measurements(obj,timestamp)
end
end
end
The object F is created which uses the methods from Feature class. Below code shows that not only we inherite from Feature class, as well as the all the properties of the Feature class are stored in the features_idlookup.
>> F = FeatureDatabase()
F =
FeatureDatabase with properties:
mtx: []
features_idlookup: [1×1 Feature]
featid: []
to_delete: []
How can I inherite from the superclass and store all the properties only in features_idlookup?
I want to achieve the following. Suggestions and help is appericiated. Thank you in advance.
>> F = FeatureDatabase()
F =
FeatureDatabase with properties:
mtx: []
features_idlookup: [1×1 Feature]

採用された回答

Steven Lord
Steven Lord 2020 年 8 月 5 日
Should FeatureDatabase inherit from Feature (be a Feature?)
Or should FeatureDatabase have a property that contains an array of Feature objects? In this case, FeatureDatabase should not be a subclass of Feature.
  1 件のコメント
Ravindra
Ravindra 2020 年 8 月 5 日
Thanks....for clearing the confusion!!
Indeed it suppose to contain an array of features.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubclass Definition についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by