---
title: "Extract Interface"
type: "refactoring-technique"
slug: "extract-interface"
url: "http://localhost:3000/en/extract-interface.md"
category: "Dealing with Generalization"
description: "Problem: Multiple clients are using the same part of a class interface. Another case: part of the interface in two classes is the same. Solution: Move this identical portion to its own interface."
---
# Extract Interface

> Problem: Multiple clients are using the same part of a class interface. Another case: part of the interface in two classes is the same. Solution: Move this identical portion to its own interface.

## Problem

Multiple clients are using the same part of a class interface. Another case: part of the interface in two classes is the same.

## Solution

Move this identical portion to its own interface.

## Why Refactor

1. Interfaces are very apropos when classes play special roles in different situations. Use [Extract Interface](/extract-interface) to explicitly indicate which role.
2. Another convenient case arises when you need to describe the operations that a class performs on its server. If it’s planned to eventually allow use of servers of multiple types, all servers must implement the interface.

## How to Refactor

1. Create an empty interface.
2. Declare common operations in the interface.
3. Declare the necessary classes as implementing the interface.
4. Change type declarations in the client code to use the new interface.
## Relations

**Similar techniques**

- [Extract Superclass](/en/extract-superclass.md)

