# UML Interface

**In short:** A UML interface is a contract that lists operations without implementing them. Classes or components realize it. Clients rely on the contract, not on the implementation behind it.

## Explanation

An interface in UML (the Unified Modeling Language) is a contract. It names operations that something must offer. It does not say how they work. You cannot create an object directly from an interface. A class or component has to realize it, meaning it supplies the real behavior. In Java, a class uses the `implements` keyword. In C#, the class lists the interface after a colon in its declaration.

**Interface versus abstract class.** An abstract class can share state between related types. A C# interface cannot hold instance fields or constructors, and its members are public by default. A class can implement several interfaces but inherit from only one base class. So abstract classes suit related types that share state. Interfaces suit contracts that span unrelated hierarchies.

**Two ways to draw it.** The explicit form is a class box marked with the «interface» stereotype. The compact form is a lollipop. A ball shows an interface that something provides. UML 2 added the socket to show an interface that something requires. Microsoft popularized the ball. The article Provided and Required Interface covers this in more depth.

**Component diagrams.** In a component diagram, the provided interface appears as a ball. Ball-and-socket is an accepted way to present interfaces there. One expert notes that mating a ball with a socket was ruled an error outside composite structure connectors. UML 1 used a dependency instead.

**Why architects care.** A black box exposes only its responsibility and its input and output interfaces. A user needs nothing more. The inner workings can change without clients having to adapt. This is information hiding.

## Example

A shop system defines an interface `PaymentService` with one operation, `charge`. Two classes, `CardPayment` and `InvoicePayment`, each realize it. The checkout component depends only on `PaymentService`. In the diagram, the payment components show a ball for `PaymentService`, and checkout shows a socket for it.

## Trade-offs

Interfaces cannot hold instance fields or constructors in C#. If related types need shared state, an abstract class fits better. A class can inherit only one base class, but it can implement many interfaces. The ball-and-socket shorthand is compact, but it hides the operation list, so use the class box when readers need the details.

One interface, realized by two classes and used by a client.

```plantuml
@startuml
interface PaymentService {
  +charge()
}
class CardPayment
class InvoicePayment
class Checkout
CardPayment ..|> PaymentService
InvoicePayment ..|> PaymentService
Checkout ..> PaymentService : uses
@enduml
```

## Checks

- Each interface shown in a component diagram is drawn as a ball (provided) or socket (required), or as a class box with the interface stereotype.
- Black-box building blocks describe their responsibility and their interfaces, not their internals.
- No interface is shown as instantiated; each is realized by at least one class or component.

## Related

- [Provided and Required Interface](https://arc.fuet.ch/concepts/modeling-uml/provided-and-required-interface.md)
- [UML Component Diagram](https://arc.fuet.ch/concepts/modeling-uml/uml-component-diagram.md)
- [UML Class Diagram](https://arc.fuet.ch/concepts/modeling-uml/class-diagram.md)
- [Information Hiding](https://arc.fuet.ch/concepts/principles/information-hiding.md)
- [Component Connector (Assembly and Delegation)](https://arc.fuet.ch/concepts/modeling-uml/component-connector-assembly-and-delegation.md)
- [Interface Segregation Principle](https://arc.fuet.ch/concepts/principles/interface-segregation-principle.md)
- [Loose Coupling](https://arc.fuet.ch/concepts/principles/loose-coupling.md)
- [Component View](https://arc.fuet.ch/concepts/documentation/component-view.md)

## Sources

- [Interfaces (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)](https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html) — docs.oracle.com, accessed 2026-11-09
- [Tip 5-6: Hide the inner workings of blackboxes! | arc42 Documentation](https://docs.arc42.org/tips/5-6/) — docs.arc42.org, accessed 2026-11-09
- [Interfaces - define behavior for multiple types - C# | Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/interfaces) — learn.microsoft.com, accessed 2026-11-09
- [Ball And Socket](https://martinfowler.com/bliki/BallAndSocket.html) — martinfowler.com, accessed 2026-11-09
- [Component diagram - Wikipedia](https://en.wikipedia.org/wiki/Component_diagram) — en.wikipedia.org, accessed 2026-11-09
