This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes How can prevent Interface inheritance to another class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "How can prevent Interface inheritance to another class?" Watch "How can prevent Interface inheritance to another class?" New topic
Author

How can prevent Interface inheritance to another class?

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Hi All,

Can we prevent inheritance for other class and want to give access to know class?

There is a interface A_Plan put in same package.





so above code is fine as want to give access to airtel for Plan A not want to give access this plan to Virgin Mobile or Vadaphone.

But Vadaphone class can access my Plan A using import pkg.interfacename.


So is there any way so that i want to restrict the inheritance of the above plan A to other class B.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2415
    
  28

Inheritance is wrong here. Inheritance should have IS A relationship. In your case, Airtel IS NOT A Plan A
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
you mean to say A_Plan should be class or abstract class and it should extend not implement the interface as below

public class AirTel extends A_Plan{

do you mean is this is IS-A relation?

please confirm.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2415
    
  28

IS A relation means exactly what it sounds like. Is Airtel a A_plan? No. then Airtel shouldn't extend A_Plan. Does Airtel provide A_Plan? yes. then AIrtel should have a method that returns A_Plan
 
 
subject: How can prevent Interface inheritance to another class?