Hot answers tagged

113 votes
Accepted

What is the use of DTO instead of Entity?

Whenever a developer asks "what's the point of doing this?", what they really mean is "I see no use case where doing this provides a benefit". To that end, let me show you a few ...
Flater's user avatar
  • 48.7k
88 votes

Are there exceptional cases where we can accept duplicate code?

Sandi Metz, a renowned software engineer and author in the Ruby ecosystem, has a great blog post and a talk where she also talks about the relationship between duplication and abstraction. She comes ...
larsbe's user avatar
  • 938
70 votes
Accepted

Are there exceptional cases where we can accept duplicate code?

Duplication can be the right thing to do, but not for this reason. Saying "we might want these three places in the code base to behave different even though right now, they're identical" is not a ...
Kilian Foth's user avatar
34 votes

Are there exceptional cases where we can accept duplicate code?

If people start reasoning about design with the words "if tomorrow", this is often a big warning sign for me, especially when the argument is used to justify a decision which includes extra work and ...
Doc Brown's user avatar
  • 206k
19 votes
Accepted

Structure of RESTful Service with Java Spring for Beginner

Here is one of my favorite kick-off examples of structure for your spring rest app. 1. Separation of layers, each layer is an individual module/project REST API Packaged as war (Could be jar if ...
Minjun Yu's user avatar
  • 306
18 votes
Accepted

Project Structure of Domain Driven Design in maven Java Spring-Boot

Your new architecture is also not derive from Domain Driven Design. Of course in context of tactical patterns (as strategy patterns scope go beyond the code). In Domain Driven Design you have plenty ...
Tomasz Maciejewski's user avatar
17 votes

In which layer should validation be located?

Both controller layer and service layer expose certain interfaces. Interfaces define contracts on how the interface should be used. Contract usually means which arguments (and its types and values) ...
qbd's user avatar
  • 2,886
17 votes
Accepted

Microservice architecture shared domain models

If you did go for microservices to benefit from scalability, loose coupling, and easy independent modification of each service, the you should stick to it to the maximum possible extent. Overall ...
Christophe's user avatar
  • 76.7k
17 votes

DDD - Is anemic domain model an antipattern? Shoud we be using rich domain models?

ADM is a good pattern for a solution of distributed services such a microservices. It fits many of today's web based business cases. Consider if we have an Order Domain object. With an OOP approach ...
Ewan's user avatar
  • 74.7k
14 votes

Are there exceptional cases where we can accept duplicate code?

Duplication to prevent coupling. Let's say that you have two big systems and you force them to use the same library. You may be coupling the release cycle of both systems. This may not be too bad but ...
Borjab's user avatar
  • 1,339
12 votes

API Gateway (REST) + Event-Driven Microservices

Repeat after me: REST and asynchronous events are not alternatives. They're completely orthogonal. You can have one, or the other, or both, or neither. They're entirely different tools for ...
Jack's user avatar
  • 4,469
12 votes
Accepted

Are Spring beans declared as static a poor design choice?

Static is not a good idea, for many reasons: They are harder to mock in unit tests Permanent memory consumption¹ Is procedural And some other disadvantages Almost every disadvantage above can also ...
Dherik's user avatar
  • 2,446
11 votes

Java: Is it okay to abuse Spring beans (@Component) rather than use static final utility classes?

The prevailing assumption that static methods are not unit-testable seems to have arisen from developers being accustomed to writing unit tests against instantiable class instances, and all of the ...
Robert Harvey's user avatar
11 votes
Accepted

Data Objects for each layer(DTO vs Entity vs Response objects)

There is no "correct" answer here. It's really about finding the tradeoffs you're happy with. Sharing one model across layers trades coupling for development speed. It will allow you to get your ...
MetaFight's user avatar
  • 11.6k
11 votes
Accepted

“Depend on abstractions, not on concretions” what is the exact meaning of this term

Depend on abstractions, not on concretions It means, coding to interfaces, not to concrete classes? For languages that support interfaces, this is generally the case. But that abstraction layer can ...
David Arno's user avatar
  • 39.2k
11 votes

“Depend on abstractions, not on concretions” what is the exact meaning of this term

Depend on abstractions, not on concretions. It means, coding to interfaces, not to concrete classes? Also known as "coding to the interface (not to confuse with interface the keyword), not the ...
Deduplicator's user avatar
  • 9,031
10 votes
Accepted

Does the use of frameworks make it unnecessary to learn design patterns?

Most frameworks already use a lot of known software design patterns. So you are using design patterns unknowingly. That said, I would strongly suggest you try learning at least the most common ones. ...
Tulains Córdova's user avatar
9 votes

Does the use of frameworks make it unnecessary to learn design patterns?

Remember, the original GoF book has the full title "Design Patterns. Elements of Reusable Object-Oriented Software.". And most of the GoF patterns have that purpose - build software which can be put ...
Doc Brown's user avatar
  • 206k
9 votes
Accepted

How to write dynamic (non ORM) repositories that can return only the necessary data without creating many methods or data-objecs?

It would be wasteful to always fetch the entire objects. First I would question this. If your objects are well-designed and not too bloated, the performance and memory overhead of fetching them ...
Doc Brown's user avatar
  • 206k
8 votes
Accepted

Client-side Rendering vs JSP's for Spring MVC Front End Dev

The JSTL syntax required to make highly-interactive pages via JSP's is getting awfully unwieldy. I'm worried that, when we expand our project and bring on more engineers, there will be a steep-ish ...
Robert Harvey's user avatar
8 votes
Accepted

What typical hardware improvements can be made to improve a Web app's performance?

Before blaming Hibernate for performance issues, you should profile your application. By profiling a given request (if the whole application feels slow, just take any request), you'll get a more ...
Arseni Mourzenko's user avatar
8 votes
Accepted

How to compare passwords which is stored in DB in encrypted form in secure way?

Question- If are storing passwords in encrypted format in DB and in future when user login into our website how will we perform authentication? You never, ever store passwords encrypted. Never. ...
Jörg W Mittag's user avatar
7 votes

Why is a Spring's HttpClientErrorException an unchecked exception?

I think you are doing well. See it from this point of view. Unchecked Exceptions - Controversy. If a client can reasonably be expected to recover from an exception, make it a checked exception. If a ...
Laiv's user avatar
  • 14.6k
6 votes
Accepted

How can I plugin new JARs implementing an interface dynamically?

After looking into a related post on Stack Overflow, I found there to be a variety of different tools at my disposal to do "plugin" style development. First, I was close with "API" but the correct ...
Walls's user avatar
  • 233
6 votes

REST is not appropriate for business applications because of necessary to distribute business logic accross layers. REST alternative required!

There is a gross misconception somewhere. I think it is near this idea. In Spring+JSF application all the business logic was encoded in special layer - Spring entities and services. In Spring+REST+...
VoiceOfUnreason's user avatar
6 votes

Client-side Rendering vs JSP's for Spring MVC Front End Dev

Although, the question may be answered and you decided to accept this answer, I want to highlight the topic from another side. 1) JSP as a templating system As a templating language, I think, JSPs ...
Thomas Junk's user avatar
  • 9,533
6 votes

In which layer should validation be located?

Hibernate validations are checks over the integrity of the data. In order to avoid RuntimeExceptions from DB. They are pretty much the same validations you should control with DB constraints, because ...
Laiv's user avatar
  • 14.6k
6 votes
Accepted

Why is it such a bad idea to share an interface between server and client?

The reason as stated in comments is that it results in tightly coupling your client platform to your server platform. Here, that means your client is required to use the language/platform you are ...
Kasey Speakman's user avatar
6 votes

Best place to convert one object to another object

This seems like a perfectly good example of using Adapter Pattern Basically, you would create one interface that would have one method: public interface Adapter { ClassC ConvertObject(); } And ...
Vladimir Stokic's user avatar
6 votes

Java: Is it okay to abuse Spring beans (@Component) rather than use static final utility classes?

Here is my rule of thumb. Use static utility classes if the methods are just 1-2 lines and perform operations which are easy to name with just a word or two, and which are very unlikely to ever change....
Michał Kosmulski's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible