-2

I have a particular class from the package: org.jdesktop.swingx.JXErrorPane.

I used a factory class to call the methods in the JXErrorPane class, while I forbid any other classes to call JXErrorPane. Any other class which needs to use JXErrorPane class needs to call the factory class.

I found on this website:http://www.eclipsezone.com/eclipse/forums/t53736.html on how to forbid accessing to a particular class or package, but it would forbid my factory class as well.

Is there a way to only allow the factory class to visit the API class but forbids any other classes?

  • Do you have control over `JXErrorPane`? If so, you could make it `package-private` and place your `Factory` in the same package with a `public` modifier. Then only the classes in the same package (e.g. your factory) can access `JXErrorPane`. – Jaims May 04 '16 at 14:32

1 Answers1

0

Your question is a bit strange but here's my two cents worth: Access modifiers should be your friends. The default access modifier at a class level would make sense if you don't want the class to be visible outside your package. A default constructor would restrict the construction of your object to be visible inside the package only. I'm assuming this is the application of the factory you're referring to in your question. Factories are for creating objects.

As for restricting invocations to the methods to your factory, that's not a correct application of a Factory. Maybe you're looking for either the Proxy or Delegate pattern. Even in that case, access modifiers are your friend. I'm not sure why you'd want such complexity though

Fana Sithole
  • 340
  • 3
  • 10