Course contentsShow
← Software Engineering
Lesson 218 of 1,9336. SOLID PrinciplesFree lesson

Role Interfaces and Interface Segregation

Apply role interfaces to define contracts based on client perspectives rather than provider capabilities.

Role Interfaces and Interface Segregation

What you'll learn: How to design interfaces around what clients need to do (roles) rather than what providers can do (capabilities).

What Are Role Interfaces?

A role interface defines a contract from the perspective of a specific client's needs, not from the service provider's full capabilities. Instead of creating one large interface that describes everything a class can do, you create small interfaces that each represent a distinct role or job a client needs performed.

Think of it like hiring contractors: you don't hire "Bob who can do plumbing, electrical, carpentry, and landscaping." You hire "a plumber" when you need plumbing, and "an electrician" when you need electrical work—even if it's the same person. Each role has its own contract.

Client Perspective vs. Provider Perspective

Provider-centric thinking: "This class can print, scan, fax, and email documents, so the interface should have all those methods."

Client-centric thinking (role interfaces): "My invoice generator only needs printing, so give it an IPrinter interface. My document archiver only needs scanning, so give it an IScanner interface."

Even if one physical device provides both capabilities, clients shouldn't be forced to depend on methods they'll never use. Each client works with the interface that matches its role.

How Role Interfaces Support ISP

Role interfaces are the solution to Interface Segregation problems. When you identify that different clients use an interface for different purposes, create separate role interfaces for each purpose. This keeps dependencies minimal, focused, and meaningful.

Key Takeaway: Design interfaces around client roles (what specific clients need) rather than provider capabilities (everything the implementer can do), ensuring each client depends only on the methods it actually uses.