Parameter Object

DesignPattern

Name: ParameterObject

Type: Design

Problem: An API call gets huge, with TooManyParameters and/or the need to change the signature frequently during development. Most invocations use default arguments. Function overloading is unavailable or considered undesirable. Or, it is desired to expand an interface without breaking existing code. Or, you need to return multiple values and don't have reference parameters available.

Context: API development, especially for a complex class/system/function.

Forces: Need to not have to type in huge argument lists; need to aid refactoring, need to decrease coupling between a function/method and its callers.

Proposed Solution: Replace the LongParameterList with a ParameterObject; an object or structure with data members representing the arguments to be passed in.

Resulting Context:

Drawbacks:

Design Rationale: Decoupling systems.

Related Patterns:

AntiPattern you should beware of: MagicContainer. Similar to ParameterObject, but uses a generic associative container (such as a HashTable) to contain the parameters. Much slower, and you have to handle missing or superfluous parameters. (On the other hand, coupling is further reduced, and no new class need be written).

Pattern Category: CategoryStructuralPatterns

Also Known As:

Examples in the Literature:

Examples in Practice:


See also (and merge with?) ValueObject, ArgumentObject, ResultObject, PredicateDispatching

EditText of this page (last edited March 26, 2007) or FindPage with title or text search