Whats the right way to separate model and logic [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Hi I'm setting up a new project and was struggeling with Java Annotations.
Are they related to Logic / API or Model
In Detail:
I have a started a multi maven module for example:
project-parent
project-model
project-persist
project-logic1
I separated model from every other module simple POJOs with JPA.
To use them with different frontends or REST etc.
Now I wanna use annotations from project-logic1 in the model.
Now i'm confused with the seperation.
Should I make an own API module (project-API) for this and similar annotation / interfaces
Should I simply add the annotation in the project-model
Should I add the dependency of project-logic1 into the project-model POM
I think the first one is correctly but I'm not sure.

From what I understand, you shouldn't use your model objects (with the JPA annotations) as DTO in your project.
You should have your model within the logic project, so DB related items are un the same place, and you create and API project with only POJO, not related to your DB, so you can use this API for REST services' answers and keep your implementation hidden.

If you have common code, I would suggest to wrap it into a dedicated module, so I would agree with your "API"-Approach (although the label "API" might be too much here).
Do not cross-reference your modules, dependencies must always go one way. And: Never repeat yourself, so c/p-ing your annotations is fundamentally wrong ;)

Related

Sharing code between multiple micro-services [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am developing three micro-services
View offers
Add offers(for administrator)
Opt offers
View offers is used to show offers to customer and Add offer used by service admins to link offer to customer and if offer is linked to customer, view offer will return that offer in response. Opt offers is used by customer to avail the offer.
While designing, I realized that all 3 services share same functionality, but also have their own logic.
Should I use shared code while developing these API or each API must have its own code base?
If you are using maven then you can use Maven Modules. This basically means you can extract the service code into separate module and include that module as a pom dependency in all 3 microservices.
Here's an example of how to do it using Spring. If you are not using Spring then you can have a look at another example here.

Multi module java app project structure [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am getting task(for learning new technologies) to create a facebook like project with
1. Auth (Spring Boot,Spring security, MySQL, ember.js)
2. Messaging (Spring Boot, Kafka,Cassandra, ember.js)
3. Member (Spring Boot, ember.js)
4. Reporting (Kafka, Spark, ember.js)
functional.
I need to get help for project structure. Should I have four separated modules (like auth, message, member, report) + core module. And what I should put in core module(entity beans, helpers, utils...)?
Thanks in advance.
Keeping code organized on huge projects is important, making each functionality into it's own module is desired.
But only if you are experienced enough should you begin with that. It might be better to start off in one module and expand later into separate modules.
In the core you construct tests that determine if the application as a whole is functional, etc. Core could also include the REST for everything else than the modules you already said.
Or do you plan to make the front with react?

Proper organisation of packages in java standard crud application [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make a small crud application using swing, with Authentication features and GUI.
Can you give me the right organization and naming of my packages ??
There's no hard and fast rule, but the rule of thumb is to start with your company's domain name in reverse:
com.mycompany
Then add on the project:
com.mycompany.project
This ensures you're unlikely to have clashes between your classes and those from the libraries you depend on.
Then personally I try break things down by their functional groups, for example
com.mycompany.project.domain // contains the business domain classes
com.mycompany.project.io // contains the classes that deal with network or file-system
com.mycompany.project.persistence // contains the classes that handle persistence of the business domain classes
com.mycompany.project.ui // contains the user interface related classes
Within those packages, I might have further group but that would be very specific to the project.
The important thing is to be consistent across your project.
Short answer: One package per module/feature, possibly with sub-packages. Put closely related things together in the same package. Avoid circular dependencies between packages.
Long answer: I agree with most of this article

In Java design is composition not used much anymore? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
A Java developer (with lots of experience in sophisticated, high-performance environments) very recently commented that "composition is not used much anymore." I was surprised by this comment. Is this true?
On the one hand, other answers on this forum indicate that difference between composition and aggregation can be ambiguous (can the whole exist without the part; does the part exist throughout the life of the containing object?). But perhaps in all of these cases the question stands--how to add behavior to an existing class or class hierarchy.
The context of his comment was a discussion of possible alternatives to inheritance. If this developer is correct, what has replaced composition in working practice? Mix-ins through added interfaces?
Any perspectives are welcome!
If anything, it's probably used now more than ever thanks to dependency injection frameworks like Spring. The model that all of the Java developers I know use is to build classes that relate to one another in functionality more by interface and purpose and to use Spring to inject them according to a particular configuration (ex the ability to replace entire security frameworks just by changing a spring configuration file and adding a few new JAR files).

In what scenario the framework should not be used? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have the first meeting with my project manager and she assigned me a project which to be start soon. She explained to me few points related project e.g. technology, functionality, end user expectation etc.
MVC based web application
Not to use any framework
Server Side : use only Java, servlet, jsp
UI : Javascript, jQuery can also be used
integratation with existing project (at later stage)
There is one point i can not understand why she asked me to not to use any framework although i could not ask why. Does anybody clarify ? If i use any framework like spring then will it create any problem while integration with existing project.
I can recognize 2 sub questions in your question.
In what scenario the framework should not be used?
why she asked me to not to use any framework?
Answer 1
I can imagine situation when you don't need any framework. It is if you have to create extremely simple 1-2 screen application without any security, access rules and probably without DB based persistence. This means that IMHO framework-less application is good as a student exercise just to understand how things work.
Answer 2
She is ... not professional enough. I am sorry to say it but this is pretty obvious. To implement MVC without framework you have to perform a lot of dirty work. I believe that the key reason for this strange requirement is "integratation with existing project" that is probably created without any framework, so PM thinks that framework could bother you during this integration.
Moreover, product manager should never dictate R&D how to implement project. Project manager can politely ask to implement certain set of features.
I am sorry if my answer is helpful.

Categories

Resources