我有一个来自我自己的类 object 的对象,它继承自我自己的类 data 和我在MATLAB中自己的类 graphic . 要表示对象 object ,它使用 data -superclass中的属性和方法 . 现在我想用 graphic -superclass中的方法绘制我的对象 object ,但是这个超类中的方法对它的 object -subclass一无所知 .

有没有办法将 object -subclass中存储的所需数据提供给 graphic -superclass而不将此信息放入函数参数,如 object.draw(this_data_stuff) ,方法 draw 来自 graphic -superclass,数据 this_data_stuff 来自 object -subclass?

我想出的唯一方法是将子类对象 object 存储为 graphic -superclass中的属性,但将子类对象作为属性存储在超类对象中似乎很奇怪,而子类继承自同一个超类 .

编辑:

data-class:

classdef data < handle

  properties
    data_stuff
  end

  methods

    function obj = data
    end

    function obj = compute(obj)
      obj.data_stuff = ... % math
    end

  end
end

graphic-class:

classdef graphic < handle

  properties
  end

  methods

    function obj = graphic
    end

    function obj = draw(obj)
      plot(obj.data_stuff,t) % ERROR, property 'data_stuff' is unknown
    end

  end
end

object-class:

classdef object < data & graphic

  properties
  end

  methods

    function obj = object
    end

  end
end

Test:

object_A = object;  % creates object
object_A.compute;   % generates data_stuff
object_A.draw;      % draws data_stuff, Error here, because 'draw` needs access to the 'data_stuff'-property.