2017-05-03 19:48:29 +02:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Marker Interface
|
|
|
|
folder: marker
|
|
|
|
permalink: /patterns/marker/
|
2017-12-25 11:30:24 +02:00
|
|
|
categories: Other
|
2017-05-03 19:48:29 +02:00
|
|
|
tags:
|
|
|
|
- Java
|
|
|
|
- Difficulty-Beginner
|
|
|
|
---
|
|
|
|
|
|
|
|
## Intent
|
2017-05-23 01:38:02 +02:00
|
|
|
Using empty interfaces as markers to distinguish special treated objects.
|
2017-05-03 19:48:29 +02:00
|
|
|
|
2017-05-03 19:49:25 +02:00
|
|
|

|
2017-05-03 19:48:29 +02:00
|
|
|
|
|
|
|
## Applicability
|
|
|
|
Use the Marker Interface pattern when
|
|
|
|
|
2017-05-23 01:38:02 +02:00
|
|
|
* you want to identify the special objects from normal objects (to treat them differently)
|
|
|
|
* you want to mark that some object is available for certain sort of operations
|
2017-05-03 19:48:29 +02:00
|
|
|
|
|
|
|
## Real world examples
|
|
|
|
|
2017-05-23 01:38:02 +02:00
|
|
|
* [javase.8.docs.api.java.io.Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html)
|
|
|
|
* [javase.8.docs.api.java.lang.Cloneable](https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html)
|
2017-05-03 19:48:29 +02:00
|
|
|
|
|
|
|
## Credits
|
|
|
|
|
|
|
|
* [Effective Java 2nd Edition by Joshua Bloch](https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683)
|