Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have various interfaces i have to implement. Let\'s assume ITypeA, ITypeB. The

ID: 644864 • Letter: I

Question

I have various interfaces i have to implement. Let's assume ITypeA, ITypeB. They have following methods:

ITypeA
Connect
Disconnect
GetData
SetData
ClearData

ITypeB
Connect
Disconnect
GetData
SetData
Start
Pause
Stop
They have some base functionality: Connect, Disconnect, GetData and SetData. If I want to add ITypeC in the future, it will have these base functionality too.

I want to access to the base functionality and if there is additional functionality, I want to get this too. What design patterns are available that are capable of this situations?

I found one here: Extension Interface. In this, you create a base interface and multiple extension interfaces that are implementing the additional functions. In the base interface you can ask for the available extension interfaces of the component. But this approach seems complicated: I have to create interfaces for each type, factories for the interfaces, I need some tables to save what Interface belongs to what Factory...

What is the basic solution for this problem? Extension Interfaces? Are there any other possible alternatives for my problem?

Explanation / Answer

You may have more joy dividing your interfaces by behaviour and deciding on the types later.

interface IConnectable
Connect
Disconnect

interface IDataTransferrable
GetData
SetData

interface IPlayable
Start
Pause
Stop


class TypeA : IConnectable, IDataTransferrable
class TypeB : IConnectable, IDataTransferrable, IPlayable
And then how can discover if your object supports these interfaces?

here's one way:

if (ob is IPlayable)
{
Playback(ob);
}
where you have a function:

void Playback(IPlayable ob)