How to apply implementation-depended method calls?

Knigesserse

New Member
I have a \[code\]delete(object)\[/code\] method that should execute different code depending on which object is to be deleted.\[code\]class MyService { void delete(Object obj) { if (obj instanceof Foo) { //execute some foo deletion logic } if (obj instanceof Bar) { //execute some bar deletion logic } //if... and so on }}\[/code\]From the design point of view, how can I avoid \[code\]instanceof\[/code\] checks here?I cannot introduce a \[code\]delete()\[/code\] method in all of my implementations, as the objects should not know about how they should delete themselves.What else is there?
 
Back
Top