interface question

  • Thread starter Thread starter vidalsasoon
  • Start date Start date
V

vidalsasoon

//I have a class that has 2 "Render()" implementations.
//I declare them like this:

public class ComplexShape : IEffect, INoEffect{

IEffect.Render(){
...
}

INoEffect.Render(){
...
}
}

//I also have a second class that implements a single render method

public class SimpleShape : INoEffect{

INoEffect.Render(){
...
}
}


//Now my question is:

//I want to use the objects like this:

ISOMEINTERFACE shape; // <-- CONFUSION HERE. I DON'T KNOW WHAT TO
DECLARE.

if(...){
shape = (IEffect)new ComplexShape(...);
}else{
shape = (INoEffect)new SimpleShape(...);
}
shape.Render();


// How could I declare this shape object so I can use it as either
IEffect or // INoEffect

// still getting used to interfaces.
V.
 
// How could I declare this shape object so I can use it as either
IEffect or // INoEffect

You can't do that unless they share a common base type. But you can't
put the Render method in a base interface and still be able to
implement two variants of it in the ComplexShape class.



Mattias
 
Back
Top