How can I avoid infinite loop when I define my superclass?
古いコメントを表示
I wrote a superclass which defines an object filling up some of the properties with user given inputs. The value of the rest of the properties should be dependent on one of the given inputs. To be more concrete:
The superclass should have 3 properties: DataSet Type Method Parameter
The constructor should receive 3 inputs, one of them will be used as DataSet (vector of doubles), the other one is a single character, eithe 'A' or 'B', defining the type of the data set, and the EstimationMethod can be 'X' or 'Y', which specifies a method how I want to compute the parameter for a dataset.
The important thing to note is that the two Estimation methods should be different for A and B typed datasets. My idea was to define two subclasses, one for Type=A and one for Type=B. The subclasses would inherit the dataSet from the superclass as well as the EstimationMethod. In these subclasses I would like to implement X and Y EstimationMethods corresponding to Type A and Type B.
What I expect to see: In my script, when I define an onject, let's say, Object1=Superclass(DataSet1,'A','Y'), the constructor should call the Type A subclass, use the Y method implemented in that subclass to compute the parameter value, and add it as a value of the superclass object.
In my script, I don't want to call sublasses directly, but I want them to be called by the superclass. I am not sure this concept is a working one, because when I implemented it, it resulted an infinite loop. The superclass constructor called the subclass which tried to inherit properties from superclass, whi called subclass again, etc..
Could you please let me know if what I want to do is conceptually good, and if yes, help me with a sketch of the implementation?
Thank you in advance
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Construct and Work with Object Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!