Frage

I thought about interesting situation in software design. How to hide package (and public class in this package) from package that should not see it?

For example, the three software design layers (UI, BL, DAL). The UI layer should know only the BL layer, and the BL layer should know only the DAL layer.
So the BL package using the DAL package. But how can I prevent from the UI layer to use the DAL layer, without the BL layer or take advantage of the fact that the BL already knew the DAL.

This is only example of what I meant, to prevent from package to see other package without connector-package.

War es hilfreich?

Lösung

Java alone does not enable this kind of separation. As soon as a class needs to be public, its public to the world.

I feel with you, as I don't like packages with hundreds of classes, so I like to substructure them into subpackages. Unfortunately this interferes with the only hiding mechanism for classes, using package private classes.

The way one can solve this in practice is usually by separating the code into separate build units (projects, essentially). You can make a separate project for each layer, and only add the layers intended for access as dependecies.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top