Hey,
so this might be a rather vague question but anyway here it is. I am really having a hard time getting to grasp with OOP in Julia. I am developing a package for specific clinical trial designs and these designs can essentially be represented as a tuple of vectors. Trying to be thorough I implement them as parametric composite types. E.g. the base design could be
type DesignA{T1, T2}
v1::Vector{T1}
v2::Vector{T2}
end
Now another design could be just like DesignA but with additional parameters.
type DesignB{T1, T2, T3}
v1::Vector{T1}
v2::Vector{T2}
additionalParameter{T3}
end
In C++ etc. I would simply inherit from DesignA and get all methods etc. for free. In Julia, however, I cannot subtype parametric composite types (right?). So I introduced an abstract type Design
as supertype of both DesignA and DesignB and implement all methods for the base Design for this abstract supertype. E.g.
getv1(d::Design) = d.v1
This does, however, not allow to specify the return type of getv1
(which I would like to do both for safety reasons and clarity) and in general all methods for Design
cannot use the type information T1, T2 that every Design
instance has.
An alternative that came to my mind was to define Design
as a concrete type and use some kind of a mixin approach:
type Design{T1, T2, PType}
v1::Vector{T1}
v2::Vector{T2}
additionalParameter{PType}
end
My `getv1’ would then be something like
getv1{T1, T2, PType}(d::Design{T1, T2, PType})::Vector{T1} = d.v1
I think that should work fine in my particular case, but it makes later extensions of the code difficult because nobody can inherit from `Design’ and all extensions must fit in the mixin approach i.e. define a new PType and dispatch based on that.
So, please be patient with a statistician trying to wrap his head around the delicacies of OOP and help me out here. What is the Julian
way of handling such cases in the clearest possible way?
Best,
Kevin