Questions tagged [anti-patterns]

A programming anti-pattern is a commonly used solution to a specific programming problem, often claiming being an actual design pattern. But such a solution usually leads to adverse effects on an application scalability, testability and maintenance.

An anti-pattern can be thought of as a "worst of breed" solution to a problem in that it may "work" for its intended purpose, but have unwanted side effects or incur technical debt. Anti-patterns can arise from improper education, insufficient experience or simple ignorance.

SQL-Injection

In short, this is an anti-pattern of applying unfiltered user input directly to a database query string. This may seem like a quick and easy solution to querying data, however it can lead to data corruption, security breeches, and so-forth.

Example:

query-string = "select * from users where id='" + userid + "';"

Assuming the userid variable came directly from the user, an attacker can cause issues by setting the value to something that would cause unexpected behavior:

userid = "' or 1=1;drop table users"

Tight coupling

Instead of keeping two distinct parts of an application separate (CSS and HTML; Business Logic and the View in an MVC application), the parts are mingled such that a change in one necessitates a change in the other.

Example:

CSS

.yellow { color: yellow; }

HTML

<div class="yellow">foo</div>

In order to change the formatting, either the content (HTML) must be changed by substituting a different class name, or the class definition (CSS) must be changed to something that doesn't match its name.

Others

Wikipedia has other examples.

440 questions
18
votes
18 answers

Can the Diamond Problem be really solved?

A typical problem in OO programming is the diamond problem. I have parent class A with two sub-classes B and C. A has an abstract method, B and C implement it. Now I have a sub-class D, that inherits of B and C. The diamond problem is now, what…
Mecki
  • 125,244
  • 33
  • 244
  • 253
18
votes
7 answers

Is global constants an anti-pattern?

I've always thought having a class just for the sake of holding constants is a bad design. But recently, I've tried googling for it and found only that having an interface as a constants is bad an anti-pattern - no mention of using a class of…
aberrant80
  • 12,815
  • 8
  • 45
  • 68
18
votes
7 answers

How to overcome the anti-pattern "Big Ball of Mud"?

What causes a computer program to turn into a Big Ball of Mud? Is it possible to recover from this anti-pattern? Are there proven refactoring methods that can be applied?
comichael
  • 438
  • 3
  • 12
17
votes
3 answers

What's wrong with awaiting a promise chain?

I’m working on an Angular 6 application and I’ve been told the following is an anti-pattern: await someFunction().then(result => { console.log(result); }); I realize that it is pointless to await a promise chain. If someFunction() returns a…
Gibran Shah
  • 871
  • 3
  • 15
  • 34
17
votes
8 answers

How to convince people that a single class with 11975 lines of code is bad? (isn't it?)

I have a dejavu feeling when reading [What to do about a 11000 lines C++ source file?] post, but I don't think I can start taking action on my own since I do not have the authority to take action. So I think the first step is to convince people in…
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
16
votes
5 answers

What is soft coding? (Anti-pattern)

I found the Wikipedia entry on the soft coding anti-pattern terse and confusing. So what is soft coding? In what settings is it a bad practice (anti-pattern)? Also, when could it be considered beneficial, and if so, how should it be implemented?
Ola Eldøy
  • 5,720
  • 7
  • 49
  • 82
16
votes
3 answers

A Factory Pattern that will satisfy the Open/Closed Principle?

I have the following concrete Animal products: Dog and Cat. I am using a parameterized Factory method to create said products. Depending on the AnimalInfo parameter that is passed to the Factory method, a concrete product will be created. The…
Ian
  • 5,625
  • 11
  • 57
  • 93
16
votes
7 answers

Is Domain Anaemia appropriate in a Service Oriented Architecture?

I want to be clear on this. When I say domain anaemia, I mean intentional domain anaemia, not accidental. In a world where most of our business logic is hidden away behind a bunch of services, is a full domain model really necessary? This is the…
EightyOne Unite
  • 11,665
  • 14
  • 79
  • 105
16
votes
3 answers

Anemic Domain Model's vs. Domain Model in a simple domain driven design

I recently read a post on "The Anemic Domain Model Pattern" which caught my attention. As I read through this I found that the Anemic Domain Model description applied to many of the projects that I have worked on and built. I never thought of this…
Andrew Siemer
  • 10,166
  • 3
  • 41
  • 61
15
votes
5 answers

Error codes within exception vs exceptions hierarchy

Do you think it is ok to use error codes within exception to specify error type? Please take a look on this code: public class MyException extends Exception { public static final String ERROR_CODE_INVALID_NAME = ""; public static final…
Darkoboar
  • 195
  • 1
  • 1
  • 6
15
votes
2 answers

The "Enum as immutable rich-object": is this an anti-pattern?

I've often seen and used enums with attached attributes to do some basic things such as providing a display name or description: public enum Movement { [DisplayName("Turned Right")] TurnedRight, [DisplayName("Turned Left")] …
Kit
  • 20,354
  • 4
  • 60
  • 103
15
votes
7 answers

Why is double-checked locking broken in Java?

This question relates to behaviour of old Java versions and old implementations of the double checked locking algorithm Newer implementations use volatile and rely on slightly changed volatile semantics, so they are not broken. It's stated that…
Roman
  • 64,384
  • 92
  • 238
  • 332
15
votes
4 answers

I'm in an anti-pattern and I want to get out

I am developing a java webapp, using jsp/jquery/ejb/jboss. I have a web-form that enables the user to select any combination of 100 fields (all from different unrelated tables/objects) from the database. These fields are then output, via a java…
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
15
votes
18 answers

When can a design pattern make your software worse?

When can a design pattern make your software worse? I have seen a program where they used the facade pattern between the GUI and logic. They considered that no objects may be transported over this, so only primitive types were used which made it…
magol
  • 6,135
  • 17
  • 65
  • 120
15
votes
3 answers

Are single implementer interfaces for unit testing an antipattern?

In regards to unit testing, I was taught that production code shouldn't have test-related code in it. Well, I feel like I'm breaking that rule every time I try to unit test. I have a class internal to my assembly, Xyzzy. I want to dependency inject…
Jeff B
  • 8,572
  • 17
  • 61
  • 140