Reputation: 559
possibly tirval question...
I have 2 directories within a Java projects that represent (lets say) model and a view. These 2 directories are mapped in eclipse as two source folders, both on build path.
View classes can make use of model classes, the second direction (model uses view) is disallowed).
Is it poissible to configure Eclispe in that way?
Example (in IDE, while coding):
I can use aClass from model in view logic (class can be imported and so on).
I cannot use aClass from view in model logic (java error generated by Eclipse).
Thanks in advance :)
Upvotes: 1
Views: 813
Reputation: 8598
If you plan to use OSGi
and create 2 different projects for View and Model then you can achieve this. With that the class of a particular project say ViewProject
can't be accessed(imported) into another say ModelProject
unless ViewProject marks the package containing that class as exported package and ModelProject marks it as import package in the Menifest.mf
file.
Upvotes: 1
Reputation: 4058
You should look into using the default Java package system. This will allow you to split up your source code into two packages (model and view), but keep all the files within the same project.
To prevent your model classes accessing anything from your view package, you should make sure that all of your classes in the view package have a modifier of protected
(or lower).
To make sure that your view can use classes from your model package, you should make sure that all of your classes in the model package (or at least, the ones you want to be able to access) have a modifier of public
.
Upvotes: 1
Reputation: 2577
You can do this by splitting to 2 projects: model and view and add dependency between them. I don't think it is possible within one project in Eclipse. But you can write a simple processor via JSR269 to implement this (check imports).
Upvotes: 0