Why not possible to use property class validation with abstract class?
3 views (last 30 days)
In the code below class fruit_t has an abstract method that is implemented by class banana_t.
I can not instantiate a fruit_t, but I can instantiate a banana_t.
But why can I not use fuit_t for property class validation in another top class top_t?
Error message is
Error defining property 'fruit' of class 'top_t'. Class fruit_t is abstract. Specify a default value for
As property fruit is a "immutable" property of top_t it will be set in the contructor, so why does Matlab need another default value?
If fruit_t is not abstract and fruit is not assigned a value in the constructur then property fruit will be of type
fruit: [0×0 fruit_t]
Why can't matlab think the same way with abstract classes then, since there is not created instance of fruit_t.
- Either don't require a "default value" for immutable properties (because they will be set in the constructor), or
- Allow zero element arrays of abstract classes (since there are no instances, there is no problem).
classdef top_t < handle
properties (SetAccess = immutable)
function e = top_t()
e.fruit = banana_t();
classdef fruit_t < handle
y = foo(x);
classdef banana_t < fruit_t
function y = foo(e, x)
y = 2*x;