Short version:
Consider the following pseudo-code:
class Foo {
private:
abstract type myVar;
} // This class is abstract
How would you implement this behaviour in standard C++?
Long version:
I have to port a lot of Obj-Oriented code from Matlab to C++.
Note that I am the least experienced person in the world with Matlab and I do not use C++ since 2007.
I googled a lot on this topic but i couldn't find a proper answer to my question. So here I am :)
Let's say that you have this matlab class:
classdef Foo < handle
properties (Abstract, Dependent)
A
end
properties
B
end
methods (Abstract)
computeA()
end
methods (Access = protected)
function obj = Foo(bar)
obj.B = Matlab.BlaBlaBla(bar)
end
end
This class (i suppose) cannot be allocated "directly" since it's constructor is protected. Also is property "A" is Abstract (ignore for a moment the fact that is also Dependent). MathWorks tells us that this means that:
- Concrete subclasses must redefine abstract properties without the Abstract attribute, and must use the same values for the SetAccess and GetAccess attributes as those used in the abstract superclass.
- Abstract properties cannot define set or get access methods (see Property Access Methods) and cannot specify initial values. The subclass that defines the concrete property can create set or get access methods and specify initial values.
So how would you correctly translate such behaviour in C++? Would it be right if I do as follow? (By right I mean that it is not a bad design practice)
class Foo {
private:
type A;
type B;
protected:
virtual void computeA() = 0;
Foo(type bar) { this.B = SomeFoo(bar); }
}
What I think (and I may be wrong) is that if I'm doing so one will have to do
class Subclass: Foo {
protected:
void computeA(){...}
public:
type A() { computeA(); return A; } //This is A getter that grants Dependent behavior
}
Or otherwise get an error at compile time.
Am i wrong? Is there a better way to do so? Also is the that right way to translate the Dependent keyword?