I wonder which design pattern should I use in my case: I have 2 endpoints that use 2 service methods, each very similar, they differ only in invoking some different methods from the same service: My first service method (invoked by endpoint 1): The second endpoint uses very similar method that differs in protectionCommandService.sendUnprotected (deleteBBB). My secondservice method (invoked by
Tag: design-patterns
How to create a self registering factory in Java?
Factory pattern violates the OCP principle because it uses if() statements, which implies that if any class is added then the factory class has to change, being against SOLID principles. Self registering classes are supposed to address this problem according to this resource: http://www.jkfill.com/2010/12/29/self-registering-factories-in-c-sharp/. The problem is that i don’t know C#. Can someone make an example of this in
ANTLR Visitor Implementation For ArrayInitVisitorImpl
I am trying to build a visitor implementation that will convert a string array to unicode. I am using the following grammar: I have gotten as far as this: and I’m not sure how to handle the nested visiting. Any assistance is appreciated. Edit: Thank to help from Bart, I was able to come up with a final solution for
Dynamically choosing which class to create object of from json
I have an interesting problem that I’m having trouble coming up with a clean solution for. My application reads collections of json objects that it needs to deserialize to this or that class type based on a field in the json itself. I have no control over the json structure or how it gets to my application. I’ve created models
Design pattern for logging entry and exit of methods?
I have an overall design and architecture question. After looking at design patterns (decorators, chain of commands, and so on) it is still unclear to me. Requirement: I would like to have logging for both entry and exit of my methods. As of now, all my methods looks like: (Below the logging, I am also using some KPI library to
How to implement Decorator pattern in Spring Boot
I know how to implement and use a decorator pattern without Spring. Because in this pattern you yourself control the process of creating components and you can perform dynamic behavior adding. Below is an example of implementation without using Spring: I am interested in how to implement the same example but with the help of spring beans. Because I don’t
How to properly convert domain entities to DTOs while considering scalability & testability
I have read several articles and Stackoverflow posts for converting domain objects to DTOs and tried them out in my code. When it comes to testing and scalability I am always facing some issues. I know the following three possible solutions for converting domain objects to DTOs. Most of the time I am using Spring. Solution 1: Private method in
Inheritance for builders in lombok
I was trying to use lombok for my project. I have a class A: and a class B: I am getting an error saying builder() in B cannot override builder() in A, as return type in BBuilder is not compatible with return type in ABuilder. Is there some way to do this using lombok? I do not want to write
What is the solution for the N+1 issue in JPA and Hibernate?
I understand that the N+1 problem is where one query is executed to fetch N records and N queries to fetch some relational records. But how can it be avoided in Hibernate?
Polymorphism vs Strategy pattern
What is the difference between the Strategy pattern and Polymorphism in Java? I’m confused that whatever is achieved via Strategy Pattern is basically possible by polymorphism. Correct me if I’m wrong in this regard. Please, also provide me example to eradicate my confusion. Answer For me, the link from CKing post and the example in Wikipedia are clear enough, but