Let's say I have an interface FooInterface that has the following signature:
interface FooInterface {
public function doSomething(SomethingInterface something);
}
And a concrete class ConcreteFoo that implements that interface:
class ConcreteFoo implements FooInterface {
public function doSomething(SomethingInterface something) {
}
}
I'd like to ConcreteFoo::doSomething() to do something unique if it's passed a special type of SomethingInterface object (let's say it's called SpecialSomething).
It's definitely a LSP violation if I strengthen the preconditions of the method or throw a new exception, but would it still be an LSP violation if I special-cased SpecialSomething objects while providing a fallback for generic SomethingInterface objects? Something like:
class ConcreteFoo implements FooInterface {
public function doSomething(SomethingInterface something) {
if (something instanceof SpecialSomething) {
// Do SpecialSomething magic
}
else {
// Do generic SomethingInterface magic
}
}
}