Variable superclass

Hi, I currently have created the following class design: Abstract Class A and Subclass B(1) < A. As expected with implementing an abstract class, I also have Subclass B(2)<A, B(3)<A...etc. I'm interested in creating a new subclass, say C, whose Superclass will be determined at runtime. For example, I may want C<B(1) or C<B(2) and therefore I'm interested in a varaible superclass B when coding my subclass C. Is this possible? Can anyone point me in the right direction for documentation? Thanks.

댓글 수: 1

Paul
Paul 2011년 10월 31일
I found a work around solution and thought I might post it. It's not quite as elegant as might be possible in C++ but it works. Simply create objects of Subclass B(1)...B(n) in Subclass C at runtime, and instatiate the appropriate object based on a string indicator (or object indicator such as 'enum').

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
per isakson 2011년 11월 3일

0 개 추천

One way that I have used is to write an m-file at run time.
classdef C < Middle
...
At run time I write the file, Middle.m, to a special folder (to avoid copies of Middle.m in different folders)
classdef Middle < Bx
end
before calling C. If used the construct must be describe in the comments.

카테고리

도움말 센터File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

태그

질문:

2011년 10월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by