How do you show an interface and its implementations in a class diagram?
Fast recall
Quick revision
Core answer
Understanding of interface notation in UML, which is fundamental since well-designed systems use interfaces for loose coupling and dependency inversion.
Using a solid line instead of dashed for interface implementation, or forgetting the <<interface>> stereotype label, making it look like a regular class.
Mention that interfaces typically define behavior contracts (PaymentProcessor, NotificationService) and explain how this enables dependency injection in Spring applications.
Interview-ready guide
Interview answer
To show an interface in a class diagram, I draw a box like any class, but I put the interface stereotype — the word interface in guillemets, those double angle brackets — above the name, and inside I list only method signatures, no instance attributes, because an interface has no state. Then each class that implements the interface connects to it with a dashed line and a hollow triangle pointing at the interface. That dashed line is the key signal; in UML it's called realization, and it specifically means implements.
The contrast is with an abstract class. There I write the class name in italics to show it's abstract, and subclasses connect to it with a solid line and a hollow triangle — that's generalization, which means extends. So the quick mental rule is dashed equals implements, solid equals extends, and the triangle always points toward the interface or parent, never away from it.
You can absolutely mix the two in one diagram, which is common in real designs. For a payment example, I might have a PaymentMethod interface with CreditCard and UpiPayment realizing it via dashed arrows, and also an abstract Wallet class that implements PaymentMethod and is itself extended by concrete wallet types using a solid arrow. Reading that diagram, you can instantly see which relationships are contracts being fulfilled and which are code being inherited, purely from whether the line is dashed or solid.
How do you show an interface and its implementations in a class diagram
Direct Answer
Draw the interface as a box with <<interface>> above the class name and only method signatures inside (no attributes). Each implementing class uses a dashed line with a hollow arrow pointing to the interface. If you have an abstract class, write the name in italics and use a solid line with hollow arrow for subclasses. You can mix both: an interface with multiple implementations, one of which is abstract with its own subclasses.
Deep Dive & Architecture
Realization means implements
An interface is normally shown as a rectangle marked «interface» with its operation signatures. A class that implements it connects with a dashed line and a hollow triangle pointing toward the interface. The arrow direction says the concrete class fulfils the more general contract.
Generalization means extends
Inheritance uses a solid line with a hollow triangle pointing toward the parent class. An abstract class may be shown with an italic name or an {abstract} marker. Visibility symbols such as + and - can be added when method and field access matters.
A payment hierarchy uses both notations
PaymentMethod can be an interface. CardPayment and UpiPayment point to it with dashed realization arrows. If CardPayment is an abstract base for CreditCardPayment and DebitCardPayment, those subclasses use solid generalization arrows. Line style distinguishes implementing a contract from inheriting a base implementation.
Code Example
interface PaymentMethod { // <<interface>> in UML
void pay(BigDecimal amount);
}
class CreditCard implements PaymentMethod { // dashed + hollow triangle
public void pay(BigDecimal amount) { /* charge card */ }
}
class UpiPayment implements PaymentMethod {
public void pay(BigDecimal amount) { /* UPI */ }
}
abstract class Wallet implements PaymentMethod { /* italic name; solid arrow from subclasses */ }
Two implementers realize the interface (dashed); an abstract Wallet can implement it and be extended (solid).
Common Mistakes & Pitfalls
- Solid line for implementation —
implementsis a dashed line; solid is forextends. - Attributes inside an interface box — interfaces show methods (and constants), not instance fields.
- Forgetting the «interface» / italic markers — without them the reader can't tell the type.
- Arrow pointing the wrong way — the triangle points to the interface/parent.
Check your understanding
Answer these without looking back at the article.
- What are the key elements of a UML class diagram?
- How much detail should a class diagram in an LLD interview have?
- How do you draw a class diagram for a simple parking lot on a whiteboard?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.