Hot answers tagged

101 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 ...
  • 38.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 ...
  • 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 ...
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 ...
  • 188k
32 votes
Accepted

Why do we need frameworks for dependency injection?

We don't need the frameworks. It is entirely possible to implement dependency injection manually, even for a relatively large project. On the other hand, using a framework makes it easier, ...
  • 17.3k
32 votes
Accepted

Java application structure: Horizontal vs vertical split

I would suggest doing neither. Trying to enforce a technical layering with a package structure leads to a lot of entanglement in your application. Not to mention the fact that we try so hard to hide ...
  • 438
23 votes

Should service layer catch all dao exceptions and wrap them as service exceptions?

I think an important factor is who your service clients are. If your service layer is just an architectural boundary between layers in your own project, and the service client is within the same ...
  • 2,933
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 ...
  • 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 ...
17 votes

Why do we need frameworks for dependency injection?

Why do we need DI (Dependency Injection) at all? The DI mechanism separates object production from object consumption. The dependecies an object needs are delivered transparently from the outside. ...
  • 9,267
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 ...
  • 69.8k
16 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) ...
  • 2,786
15 votes

Should service layer catch all dao exceptions and wrap them as service exceptions?

No, you should not wrap DAO exceptions in a web application It's a lot of noise in the code for zero benefit. DAO exceptions are unchecked exceptions for a good reason. The application code cannot do ...
  • 33.5k
15 votes

What does the Spring framework do? Should I use it? Why or why not?

What does the Spring framework do? Spring is as today not only, what was known as a simple framework, it is a complete ecosystem. Topics covered by the spring ecosystem: Spring Framework (e.g. ...
  • 9,267
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 ...
  • 1,276
14 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 ...
  • 65.5k
13 votes
Accepted

What is a transaction?

In its broadest sense, a "transaction" is a group of actions that should be performed as if they were a single "bulk" action. The term is most often used in the context of databases, but it can be ...
  • 27.3k
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 ...
  • 4,399
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 ...
  • 38.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 ...
  • 8,298
10 votes

Should service layer catch all dao exceptions and wrap them as service exceptions?

The main reason one would use exception wrapping is to prevent the code in the business layer from having to know about every possible exception in the system. There are two main reasons for this: ...
  • 213
10 votes
Accepted

Is it still a good practice to log parameters and returns?

I don't think that article is implying that every method should should be logged that way, it's just saying when you're logging make sure you capture the context in which the log occurred. For ...
  • 1,155
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. ...
10 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 ...
  • 2,277
10 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 ...
  • 11.5k
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 ...
  • 188k
9 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 ...
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 ...
  • 188k
8 votes
Accepted

Usage - Factory Pattern vs Dependency Injection

You pretty much hit the nail on the head. Dependency injection is a great choice when you want to get dependencies that are known and unchanging at runtime or compile-time, depending on how you ...
  • 6,242
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 ...

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