Passing Nulls To Constructors

Not sure if this is a CodeSmell or an AntiPattern.

This page is not complete. I'll do it as the day progresses. -- PaulMurray

As it is, it is amusingly close to a self-example :-)


CodeSmell Name: Passing Nulls to constructors

Type: Design

Problem: [what you really want to solve; present a simple concrete example]

Context: [context]

Forces: [forces]

Supposed Solution: [the bad solution; explain in terms of your concrete example]

Resulting Context: [what happens when you apply it, good and bad]

Design Rationale: [rationale]

Related AntiPatterns:

Applicable Positive Patterns:

AntiPatternCategory: [classify it]

Also Known As: [other names]


Examples in the Literature:
Examples in Practice: My practice: I use a large object layer for one particular kind of thing stored across many rows of the database. In order to completely initialize, it needs some parameters about how the image that it will draw on top of is laid out. Most of the time, I don't need that part of the layer. Therefore, I pass null for that parameter as the signal that I do not want it initialized.
CategoryCodeSmell CategoryNull CategoryDevelopmentAntiPattern

EditText of this page (last edited August 12, 2010) or FindPage with title or text search