Skip to content
Advertisement

Tag: design-patterns

Which design pattern for merging 2 methods they differ in one place

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

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

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

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

Advertisement