Skip to main content

All Questions

5 votes
5 answers
910 views

Handling class specific behavior: polymorphism vs instanceof

I'm designing a system with different types of components, and I'm trying to decide whether to use polymorphism or instanceof checks for handling type-specific behavior. I see two possible approaches: ...
3 votes
4 answers
2k views

Avoiding instanceofs with GUI composites

I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings (if a Row has no such sibling, the ...
2 votes
3 answers
951 views

Is breaking encapsulation a necessary compromise for serialization?

I've been considering the way to solve this problem for a while, and I'm currently stuck between two options I both feel are suboptimal. Here's an abstract example of what I'm dealing with: I have a ...
1 vote
2 answers
221 views

Abstraction for user notification

We have a desktop Swing application. It executes operations against a DB. It could be plain DML, it could be procedures. In both cases, it could result in an error. In that case, we need to display a ...
2 votes
6 answers
939 views

Is it ok to assert on the behavior of return values of a testable class?

So I have a dialog for generating a random password. The user can set min, max, character categories (upper, lower, etc.). What the user basically does is configuring a StringGenerator that does the ...
0 votes
5 answers
619 views

Is it bad to pass builders as constructor arguments?

Note. It's a "spin-off" from my previous question. Not a duplicate — it focuses on a different topic I got to know builders from Bloch's Effective Java. However, I made two changes to his ...
1 vote
3 answers
419 views

Should everything be buildable?

You have some class that performs a certain job public class MyClass { public MyClass() { // ... } // ... } Then, a spec change comes around. The responsibility of the class is the ...
2 votes
2 answers
276 views

Is it ok to extend utilities?

Apache Commons has StringUtils. It's great, but I wish it had a shuffle() method or similar Is it ok to create my own StringUtils that extends Apache's StringUtils and adds the method (Apache's class ...
0 votes
3 answers
151 views

Exposing dependencies results in "fat" constructor. What should you do next?

You take a non-testable class with a lot of static dependencies and expose, and expose until they are all explicitly declared in a constructor But halfway through that nice plan, you notice your ...
1 vote
3 answers
2k views

How to design an API wrapper with bulky operations on domain object? (Need guidance)

I need some guidance in designing an API wrapper for my backend APIs. I have tried to keep it as specific as possible. Context: We have a project which supports certain file operations like edit, ...
6 votes
4 answers
1k views

How to avoid init methods when 2 objects need the reference of each other?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first ...
4 votes
6 answers
2k views

The ID of an object is null at start. Does that make the object state invalid and violate encapsulation?

This question is related to How should an `Employee` class be designed? In the above question, to uniquely identify an employee, each Employee object has an id field as shown below class Employee { ...
6 votes
2 answers
3k views

Trouble with circular dependency in state machine design

I am trying to develop the structure for a basic state machine that can also take in input and produce output. I've hit a bit of a mental block in trying to figure out how to model the relationship ...
1 vote
2 answers
127 views

How do I reduce number of FieldValidator derivations?

I am trying to write RSQL Parser which checks if the RSQL is logically correct. while the RSQL Java library checks whether the RSQL expression is grammatically correct, it doesn't check if the ...
19 votes
6 answers
8k views

Is utilizing a singleton for a cache an antipattern?

I'm currently writing an MVC application and I need a class that can: A: get, add and remove data(specifically a TreeSet of sorted strings that I want stored in memory, but I doubt the data itself is ...

15 30 50 per page
1
2 3 4 5
17