In C++ I can do something like this:
class async_get_if
{
public:
virtual void get( int & ) = 0;
};
class sync_get_if
{
public:
bool empty() = 0;
bool try_get( int &t ) = 0;
};
class async_put_if
{
public:
virtual void put( const int & ) = 0;
};
class sync_put_if
{
public:
bool full() = 0;
bool try_put( const int &t ) = 0;
};
class get_if : public virtual async_get_if , public virtual sync_get_if
{
};
class put_if : public virtual async_put_if , public virtual sync_put_if
{
};
// the fifo implementation implements all four async/sync interfaces
// as well as get_if and put if
class fifo : public named_object , public virtual get_if , public virtual put_if
{
public:
fifo( const string &name , int size );
void get( int & );
bool empty();
bool try_get( int &t );
void put( const int & );
bool full();
bool try_put( const int &t )
};
// fifo method implementations omitted ...
In Dart, it's obvious enough how to do the async and sync interfaces - they would all be abstract interfaces - and how to do the fifo. But how would I do the intermediate get_if and put_if interfaces ? Is it even possible ?
PS as a partial reply to Robert Schwartz, the reason I want to do this is that I want to refer to the fifo using one of the six possible interfaces.
fifo f;
async_get_if &g1( f ); // fifo implements async_get_if
sync_get_if &g2( f ); // fifo implements sync_get_if
get_if &g3( f ); // fifo implements get_if
int get_data;
g1.get( get_data );
if( !g2.empty() ) g3.try_get( get_data );
and also:
// get_if knows it is composite of async_get_if and sync_get_if
async_get_if &g4( g3 );
if( g4.empty() ) ...
If mixins help with this, it's not obvious to me how.
Like you said, you can define the sync and async classes as abstract interfaces.
You could make them also abstract interfaces which implement the sync and async interfaces.
Define fifo as a class that implements the intermediate
GetIfandPutIfinterfaces.In the above code, fifo would conform to all 6 interfaces.