Skip to main content
116 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
  • 52.9k
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
  • 210k
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 ...
Alex Minjun Yu's user avatar
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
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
  • 78.7k
16 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
  • 77.5k
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,509
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,456
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.4k
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,081
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
  • 210k
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
  • 210k
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
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
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
6 votes

HATEOAS APIs and front end development

The benefits of HATEOAS (Hypermedia) are real for both internal and external APIs. However, the tooling is often lacking to take advantage of those benefits. Let's start with the "problem" of having ...
Jason Desrosiers's user avatar
6 votes

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

I don't know whether the interviewer asked something wrong on purpose to see whether you would correct him or he was just simply wrong. But when you used a hash function if someone breaks into the ...
FluidCode's user avatar
  • 793
5 votes
Accepted

Opportunity cost of DIY DI?

There are two legitimate reasons to DIY that I can think of: It simplifies your life. A custom solution can fit your needs exactly whereas trying to incorporate a 3rd party approach can sometimes be ...
JimmyJames's user avatar
  • 27.8k
5 votes

Unique Identifiers for classes - Java with Spring

Use an identifier that has an explicit name. Validators with explicit names make your code so much more readable: instead of BusinessGroupA having validators 'v1', 'v2', 'v3' and 'v4' the ...
JDT's user avatar
  • 6,410
5 votes

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

SOLID and DDD are orthogonal to each other, meaning they are really going in different directions from each other. You shouldn’t say that one is used to the exclusion of the other, since they can and ...
RibaldEddie's user avatar
  • 3,293
5 votes
Accepted

Should DTO have same structure as payload?

Let me reword your question in a more general fashion: there are two different representations of the same block of data (here a DTO representation and a JSON representation) there are different ...
Doc Brown's user avatar
  • 210k

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