SITUATION: Say there is a class A and an interface B.
REQUIREMENT: If any class, say C, wants to create objects of A and use them, then that class will also have to implement interface B.Is there any way to enforce this condition?
WHY: Now a question may arise as to why I want to do such a thing. The reason is that when a class C creates objects of A and uses them, then those objects call certain methods of C. I want to declare those methods in interface B, so that C will invariably implement those methods.
Since you say that objects of class
Awill call methods onC, they will have to keep reference toCsomehow. Make this reference of typeBand you are done.That is
Then in
C:That will force class C to implement interface
B.