Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can prevent Interface inheritance to another class?

 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inheritance is wrong here. Inheritance should have IS A relationship. In your case, Airtel IS NOT A Plan A
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic