| Author |
How can prevent Interface inheritance to another class?
|
Prabhat Ranjan
Ranch Hand
Joined: Oct 04, 2006
Posts: 361
|
|
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: 1275
|
|
|
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: 361
|
|
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: 1275
|
|
|
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?
|
|
|