i have spring cloud project and per microservice i think i have many packages. also i have model package witch contains entity-s and custom request response objects .
question 1 : what must be entity classes package name ? entity or model ?
question 2: where must save Searchrequest & Searchresponse and other request response classes ? in model package or i must create other package ?
question 3 : exits some Standard for package structuring ? (pleas give me link )
There is no specific standard structure, It will vary according to your need.
Mostly the SERVICE package will have all the service classes which have business logic and to connect with DAO classes, Controller will have all the rest end points, Model package will contain the pojo classes.
There is not strict rules. You have to use a naming that is self explanatory (not needed to dig into the classes content to understand its meaning). That is right for micro-service, web application, batch and any kind of applications.
I think i have many packages
The main role of packages is to sort things in a human readable way.
For example if you have 2 or 3 classes by package, you can wonder on the relevance of them.
Similarly if you have 50 classes in a package, you can also wonder if you should not split them in subpackages.
Note that the package has also a role in terms of accessibility : indeed the package private
access level allows to set/reduce the accessibility of a class or a class member to the classes of the current package. It may also be very useful in terms of design and of isolation.
About your 3 questions :
question 1 : what must be entity classes package name ? entity or model ?
In Java, entity
refers generally to JPA entity (overall in a Spring project).
While model
refers to a more general concept that includes entity
but not only since the data model can also be the DTO
objects and any data specialization of your model.
If you use a single data objects layer (JPA entities that are also used as JSON representation) , using the model
term makes completely sense. If you use several level of abstraction, a package by abstraction level makes more sense.
question 2: where must save Searchrequest & Searchresponse and other request response classes ? in model package or i must create other package ?
If these objects go through every layer : in model
, otherwise probably elsewhere.
question 3 : exits some Standard for package structuring ? (please give me link )
3) Not really but as a rule of thumb, it should be self explanatory, very clear and shared by the team of the projects to favor consistency between projects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With