2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Double Dispatch
|
|
|
|
folder: double-dispatch
|
2015-08-15 18:03:05 +02:00
|
|
|
permalink: /patterns/double-dispatch/
|
2019-12-13 21:09:28 +02:00
|
|
|
categories: Idiom
|
2021-05-19 10:49:05 -06:00
|
|
|
language: en
|
2015-12-28 15:52:44 +02:00
|
|
|
tags:
|
2019-12-13 21:09:28 +02:00
|
|
|
- Extensibility
|
2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
|
2016-01-03 21:14:30 +01:00
|
|
|
## Intent
|
|
|
|
Double Dispatch pattern is a way to create maintainable dynamic
|
2015-08-13 23:54:40 +02:00
|
|
|
behavior based on receiver and parameter types.
|
|
|
|
|
2019-12-07 20:01:13 +02:00
|
|
|
## Class diagram
|
2015-08-13 23:54:40 +02:00
|
|
|

|
|
|
|
|
2016-01-03 21:14:30 +01:00
|
|
|
## Applicability
|
|
|
|
Use the Double Dispatch pattern when
|
2015-08-13 23:54:40 +02:00
|
|
|
|
|
|
|
* the dynamic behavior is not defined only based on receiving object's type but also on the receiving method's parameter type.
|
|
|
|
|
2016-01-03 21:14:30 +01:00
|
|
|
## Real world examples
|
2015-08-13 23:54:40 +02:00
|
|
|
|
2015-08-15 18:03:05 +02:00
|
|
|
* [ObjectOutputStream](https://docs.oracle.com/javase/8/docs/api/java/io/ObjectOutputStream.html)
|