Skip to main content

All Questions

5votes
1answer
307views

What do you call an enum that translates its own values?

I see this pattern a lot, especially with countries, or more generally regions. An enum is defined with additional fields and with methods that translate to and from these values. Example: import ...
user2740's user avatar
2votes
1answer
330views

In poltergeist, whats wrong with "solely to trigger or initialize several other objects"? Isn't it is a good use of encapsulation and reuse?

After reading What differentiates function objects from poltergeists?, according to the definition of poltergeist, I still don't understand why would "poltergeist" be a bad pattern: A ...
wcminipgasker2023's user avatar
0votes
0answers
116views

Is having many thin factories an antipattern?

I need to perform the following task: for a user [email protected], store a blob of data into their dedicated data store. DataStoreService is what actually stores the blob of data in the user's store, ...
async's user avatar
3votes
2answers
511views

Creating an abstraction just for exception handling - a pattern or anti-pattern?

Assume that an external library or framework not under our control exposes a Controller API: abstract class Controller { abstract fun call(): Result } Assume that we want to handle exceptions ...
Matthew Layton's user avatar
0votes
3answers
218views

What pattern is a function that returns a component?

Ok I have a bunch of components that all have the same logic but have different css classes. So I wanted to create a sort of factory function that takes the names of the classes as its argument and ...
kaan_atakan's user avatar
0votes
1answer
267views

Is this dependency propogation an anti-pattern, and how do I remove it?

Module A contains a gap buffer for manipulating text and some associated methods. Relevant to this question is the dependency on a Module B, used for syntax highlighting of text. Module A also ...
user avatar
44votes
13answers
9kviews

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

Consider your have an enumeration that looks like this: enum ProcessingType { CONFABULATION, RETICULATION, SPLICING; } And you have a web-service that looks like this: class WebService { ...
Mathieu's user avatar
  • 1,039
1vote
2answers
651views

No trivial god-class refactoring

Consider you have the following code: class UserContainer { List<User> user; //some methods to get specific users, for example users, which are higher than 1,70meters } The User have a ...
Robin Kreuzer's user avatar
0votes
0answers
75views

Can someone suggest what pattern I used mistakenly and is it correct in this situation. Any alternative?

Client_1 uses --> IService_1 and thus Service1_impl public interface IService_1 { void DoTask_1(); } public class Service1_impl : IService_1 { private readonly IDepService_1_v1 ...
PKV's user avatar
  • 181
6votes
2answers
155views

Resource that has different state based on input parameters

Let's say I have a REST api endpoint that is getting a resource called a "purchasable" (an item that a user can purchase). Here is an example of what this might look like. Endpoint: GET /...
katmfoo's user avatar
4votes
5answers
1kviews

How to fix a pair of tightly coupled classes that store references to each other?

I have the following situation: class User { public Thing curThing; } //each thing can only belong to one user at a time //And vice versa class Thing { ...
Arturo's user avatar
0votes
1answer
395views

Is an antipattern returning differente objects in a single rest method?

I have seen around the Internet several rest web services with the following behaviour. In case there are any errors, they return a Error object, otherwise they return, say, MyClass. See the ...
joninx's user avatar
116votes
17answers
24kviews

Why should 'boneheaded' exceptions not be caught, especially in server code?

I am confused because in quite a few places I've already read that the so-called 'boneheaded' exceptions (ones that result from bugs in code) are not supposed to be caught. Instead, they must be ...
gaazkam's user avatar
  • 4,519
2votes
3answers
472views

Swappable state object or decoupling data and functions

I come from OOP pradigm and I also know a bit about functional programming and its advantages. Over time I came to like the separation of data and transformations that are applied to it using pure ...
konrad's user avatar
0votes
1answer
180views

How to bring a code to conformance with tell, don't ask without creating tons of methods on other classes?

It used to be fairly common for people to call a getter, do some calculation on it, then call a setter with the result. This is a clear sign your calculation actually belongs to the class you called ...
gaazkam's user avatar
  • 4,519

153050per page
close