Skip to main content
118 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
  • 58.1k
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
  • 218k
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
15 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
  • 81.9k
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
13 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 be ...
Dherik's user avatar
  • 2,504
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 entirely ...
Jack's user avatar
  • 4,529
12 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 be ...
David Arno's user avatar
  • 39.6k
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,129
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
  • 218k
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
8 votes
Accepted

Should business logic classes be POJO only?

I read about three-tier architecture and I have a question: I read that in business logic (that is, what is in logic tier) there should be bare Java classes, These bare Java classes are called POJO's ...
candied_orange'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
  • 801
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,303
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
  • 218k
5 votes
Accepted

Creating interface fields to inject vs Objects?

What you're observing is actually called "coding to an interface." Like dependency injection, it's a technique for keeping your code loosely coupled. That's why you tend to see them used together. ...
MetaFight's user avatar
  • 11.6k
5 votes
Accepted

Should I create a Repository Container to get my repositories?

No, you should not. Simply hiding the dependencies by another service class will not suddenly make your controller better. Injecting the repositories into your controller directly is much better, ...
Andy's user avatar
  • 10.4k
5 votes
Accepted

IEC 62304, Are Software Frameworks (Spring/JEE/Angular/React) considered SOUP?

Keep in mind that I'm not familiar explicitly with IEC 62304 (it's for medical device software and I've never worked with medical devices), I am familiar with similar standards, such as ISO 9001 and ...
Thomas Owens's user avatar
  • 85.2k
5 votes
Accepted

How to deal with large data in Websocket message?

I'll propose an answer since it's been nearly a year. As @Walfrat has pointed out: Note that if you're echanging too much data, it might also be a design problem that would lead to poor ...
Jeff's user avatar
  • 1,854
5 votes
Accepted

How to reduce dependency on IOC Framework (Frameworks in general)

The easiest way to avoid dependencies on a framework is to not use a framework. Abstracting frameworks just doesn't work in practice. For example Microsoft tried creating an abstraction over their ...
David Arno's user avatar
  • 39.6k
5 votes

performance suggestions on Aggregate root containing thousands of child entities

Leaky Abstractions and Abstraction Bypasses When the abstraction breaks, and bypassing it feels prefferable, its time to fix the abstraction. Find a cheap way to speed it up, and put off actually ...
Kain0_0's user avatar
  • 16.5k
5 votes

Layered architecture horizontal dependencies

As usual, it all depends. If your application is basically a big ball of mud, with a single database and a complex data model underneath, where each JpaRepository is nothing more than a mirror of a ...
mtj's user avatar
  • 2,360

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