I have been doing research on the factory design pattern and was wondering if the below example, while not “textbook” is technically a correct use of it. Is there another design pattern that may fit the situation better? Answer IMO: Looks like the given code example actually implemented the Factory Method pattern with using the Method Object solution https://refactoring.guru/replace-method-with-method-object. Because
Tag: design-patterns
Nested for-loop problem with descending number
I’m trying to figure out how to complete this problem. I’m shooting for: and I have the following code, which gives me this: I think I’m close but can some one help? } Answer I think the problem is with the logic you used. I made an algorithm inspired by another idea, maybe it will help you. I am sure
What is the meaning of breaking code while implementing new features?
I was reading a text about SOLID principles and Open/Close principle and it said that : “The main idea of this principle is to keep existing code from breaking when you implement new features” what it means by breaking code? Answer You “break” existing code when you modify it in a way that prevents it from working for existing or
Design pattern for Java Spring data JPA projects [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 months ago. Improve this question This is my current project design Controller-> service -> Repository I am trying to understand : What layer(Name) i can
Is Spring Integration a good framework to implement the Transactional Outbox pattern? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 9 months ago. Improve this question I’m implementing Transactional Outbox pattern using Java. The Message Relay Service will poll the Outbox table for entries, and after an
How to use iterator pattern in java to load file into hashmap in batches
I have a large file containing two million lines . I’m looking to traverse through each line of the file and, process it into a key value pair and store it into a hashmap to make comparisons later on. However, I do not want to have a hashmap with 2 million key value pairs in the interest of space complexity.
What is the name of the design pattern where I dynamically pick the correct implementation based on data?
Originally I picked the correct User implementation, based on domain and realm data from the Java EE server. However that was company code, so I had to rewrite the example with numbers. I hope the underlying pattern is still understandable though. For those unfamiliar with CDI, @Inject Instance allows you to iterate through all implementations of an interface. Answer I
How to inject the right bean implementation according to a RequestParam in the current call
I have this Spring bean (this RestController for the sake of the example) that, depending on the country (let’s say a param that comes in), I want to inject the right implementation of the TaxpayerNameService. So, I have that TaxpayerNameService interface and two (more in the future) implementations of such interface which needs to be injected in the current call
Object is modified implicitly in one method and used by another
I have two methods meth1 and meth2. meth1 takes in an input of a set set1, returns a value, and also modifies set1. Now meth2 uses this set1 to compute another return value. The issue I see with this code is that the set modification is implicit and would be missed by a coder who is not careful enough. I
Avoiding circular depenency between Arena and Portal
I’m trying to resolve this ciruclar dependency while preferebly keeping both objects immutable. Basically, I need portal to be able to activate itself, and start the arena. Opposite, I need Arena to reset & close itself, and the portal. I found a solution by having two HashMap’s <Arena, Portal> and <Portal, Arena>, however I want to figure out if it’s