inheritance - Best practise for implementing multiple interfaces in C# -


i working within framework following:

imyclass instance = session.getallobjectsoftype("imyclass")[0]; ilock lock = instance ilock; if(lock != null) {    lock.lock();    instance.dosomething();    lock.unlock(); }  isaveable saveable = instance isaveable; if(saveable != null)    saveable.save(); 

for work have

class myclass : imyclass, isaveable, ilock {  } 

i reality have 8-15 interfaces need implement , need accessable casting main object. cleanest way implement this? looked facade patter, dont think can used here.

based on comment:

i hoping there better way obvious one. there lot of code going realisation the different interfaces, , ilock interface not need know isavebale functionalty. looking clean way not result in 1 class 5k lines of code , 200 public functions

if want class implement interface class need inherit interface functionality injected , wrapped (aka facade).

this cleanest way achieve goal of generic separate code classes isaveable, ilock etc.

for example:

public myclass : imyclass, isaveable, ilock {     private readonly isaveable _saveableimplementation;     private readonly ilock _lockimplementation;      public myclass(isaveable saveableimplementation, ilock lockimplementation)     {         _saveableimplementation = saveableimplementation;         _lockimplementation - lockimplementation;     }       public void isaveable.save()     {         _saveableimplementation.save();     }      public void ilock.lock()     {         _lockimplementation.lock();     }  } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -