Rokko_11
Rokko_11

Reputation: 937

Best practice for package-structure

I have following situation:

I have a package x with class A which uses classes B and C. The access level of classes B and C is package-private. B and C implement the same public Interface I.

For a better organisation of code I would like to group classes B, C and I into another package y, but WITHOUT changing the access level to public.

How can I do this? Are there some other ways than to create a public proxy class D in package y with some static factories producing instances of I?

Kind regards, Rokko_11

Upvotes: 0

Views: 65

Answers (1)

GhostCat
GhostCat

Reputation: 140427

Don't let "status quo" dictate your design decisions.

You are already doing "refactoring"; then: if there are good reasons to make B and C visible; then make the essential parts of those classes public. If not, don't do it; and keeps things package-local.

That really depends on your concrete application; and how B and C are used today. This decision can't be made by other folks on stackoverflow.

Side note: just because you need a factory; that doesn't imply that things need to be static. To the contrary - you want to avoid "static" stuff as much as possible; as unwise usage of "static" very often breaks your ability to do reasonable unit testing.

Upvotes: 1

Related Questions