Link to home
Start Free TrialLog in
Avatar of Unimatrix_001
Unimatrix_001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Some sort of interface method needed?

Hi all,

I've got a normal class that does a couple of things, nothing fancy. I want an interface method, so that:

///A.java
B mb=new B();

///B.java
//When something happens in this class, call an interface method (Z for instance) in this class.

However, when the method Z in B.java is called, I want the exact same method to be called in A.java. It seems like I need some interface method, where you can't create an instance of class B unless the class creating the instance (A) has this interface method (Z) in it... Anybody any ideas on how I can do this?

Thanks,
Uni
SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aozarov
aozarov

BTW, I agree with imladris that most normal code will not need such functionality and this sort of problems can be solved by a better object oriented design.
But still, the above logic will work if needed (in those rare cases).
Avatar of Unimatrix_001

ASKER

Agreed, it does go against the grain so to speak of OO design, but that is what I need... thank you both. :-)