Act depending on class instance
I have a ClassB inherited from ClassA. ClassA has a nested ClassC with a methodA() in it. In this methodA() I need to do things depending on condition if the outer class ClassA or ClassB. What is the best way to construct if/else statement? Thank you.
I would better add some virtual methodB in ClassA and override it in ClassB, and call it in methodA of classC.
This is not how OOP works - what if someones extends ClassB to ClassD and you want to further change behavior?
Anyway, instanceof keyword may help you while you refactor your code.
Remember that one of the purposes of inheritance / interfaces and so is to prevent big chains of if/else statements - hiding them into methods won't help getting your code smoother.