mardi 8 novembre 2016

Best practise for implementing multiple interfaces in C#

I am working within a framework where you do the following:

IMyClass instance = Session.GetAllObjectsOfType("IMyClass")[0];
ILock lock = instance as ILock;
if(lock != null)
{
   lock.Lock();
   instance.DoSomething();
   lock.Unlock();
}

ISaveable saveable = instance as ISaveable;
if(saveable != null)
   saveable.save();

For this to work I have

class MyClass : IMyClass, ISaveable, ILock
{

}

I reality I have something like 8-15 interfaces I need to implement and they need to be accessable by casting the main object. What is the cleanest way to implement this? I looked into the facade patter, but I dont think that can be used here.

Aucun commentaire:

Enregistrer un commentaire