can code snippet below be rewritten in a better way

Hi

I have written a simple code snippet I feel there has be other ways in which this code could be improved upon. Any assistance in this regard is highly appreciated

the code is as below:

if (objinstanceof Foo1 ||

objinstanceof Foo2 ||

objinstanceof Foo3 ||

objinstanceof Foo4 ||

objinstanceof Foo5 ||

objinstanceof Foo6){

// do something

}

thanks in advance

[754 byte] By [ilango171a] at [2007-10-3 2:52:20]
# 1

Yes. Move the functionality in question into the various Foo* objects, using the same method name each time.

If the implementation is the same over groups of Foo* objects, then use inheritance of composition to share it. (for example if Foo1 - Foo6 would share that same block of code, but Foo7-Foo12 do something else).

If there are only those six Foo* classes, why are you checking?

paulcwa at 2007-7-14 20:41:18 > top of Java-index,Java Essentials,New To Java...
# 2
Make an interface with no method called a marker interface. have every foo implement that interface.then just check instance of the interface.
Norweeda at 2007-7-14 20:41:18 > top of Java-index,Java Essentials,New To Java...