Skip to main content

All Questions

6 votes
7 answers
7k views

How to avoid repeating "a==b" when comparing "condition a" and then "condition b" and then...?

For example, I have an object: public class Obj{ public int a; public float b; public String c; } I need to find best "Obj": largest a and then largest b and then longest c: int ...
wcminipgasker2023's user avatar
2 votes
1 answer
846 views

Better way to implement a feature with turn on/off based on a flag

I'm trying to implement a feature with option to turn it on/off based on a flag. I'm doing it in the following way which I feel like a overkill, public interface Feature { public interface ...
Tom Taylor's user avatar
2 votes
2 answers
971 views

Design pattern for static fields of a subclass

I'm creating a library, and I want there to be an abstract class called Optimizer. The user should be able to choose from a set of predefined Optimizers and if desired, use fluent methods to change ...
Kartik Chugh's user avatar
7 votes
2 answers
421 views

How should separated methods be used?

Among other things, the CQRS has a rule that each of the methods has one responsibility. So we can't have this in the model: public class Store { public Item getOrCreateItem(int id) { ...
losasafo's user avatar
0 votes
2 answers
735 views

Question on refactoring and code design

Suppose, I have a class with a constant static final field. Then I want in certain situations that field to be different. It still can be final, because it should be initialized in constructor. My ...
dhblah's user avatar
  • 1,381