How to package Factories in Java

Aly picture Aly · Dec 12, 2009 · Viewed 7.6k times · Source

I was wondering how to package the factories that I have in my application. Should the Factory be in the same package as the classes that use it, in the same package as the objects it creates or in its own package?

Thanks for your time and feedback

Answer

Francis Upton IV picture Francis Upton IV · Dec 12, 2009

Usually factories are in the same package as the objects they create; after all their purpose is to create those objects. Usually they are not in a separate package (there is no reason for that). Also having the factory be in the same package as the objects they create allows you to exploit package visibility.