Re: Good idea or gimmick: Go-style OO-programming in C++ ?
On Thursday, 28 February 2013 17:27:34 UTC+2, jet...@web.de wrote:
But why interface may not contain checks that it is correctly used
and implemented? I constantly use exactly such interfaces:
class Interface
{
public:
/// doc describing what interface does for outside world
RetType AMethod( Param param )
{
if ( param.isBad() )
throw std::invalid_argument( "Interface::AMethod passed"
" argument 'param' should not be bad.");
if ( !isPreparedForAMethod() )
return RetType();
RetType ret( doAMethod( param ) );
if ( ret.isTrash() )
throw std::logic_error( "Interface::AMethod the implementation"
" returned trash that it should not.");
return ret;
};
private:
/// doc describing what implementer should implement here
virtual bool isPreparedForAMethod() const = 0;
virtual RetType doAMethod( Param param ) = 0;
};
Ok, you say it is *not* interface but why should I care? For me it is exactly
the *correct* way to implement an interface. It keeps concerns of interface
semantics and its implementation separated.
This looks to me at first sight like you were using multiple inheritance to
do programming with traits, see http://www.codecommit.com/blog/scala/scala-
for-java-refugees-part-5
Not sure, it is in C++ called:
"Public Overloaded Non-Virtuals Call Protected Non-Overloaded Virtuals"
Rest call it sometimes as "template method design pattern".
Nothing bad about it. But you can't do that in Java since Java interfaces
contain definitions only.
That I know.