# Interface Segregation: Small Promises

When one big promise makes every course answer for attendance, labs and a final exam, a course with no labs has to fake its answers, and the fakes end up on the lab report; the interface segregation principle says to make small promises, so each class keeps only what it can and each piece of code asks only for what it uses.

Journeyman · OOP · Updated November 17, 2026

By Gregor Dzierzon

## After this lesson you can

- Split a large interface into small promises, so each class keeps only what it can
- Spot a promise too big for its classes: fake zeros, empty methods and "not supported" errors

## Key takeaways

- A promise (an interface) that's too big forces classes to answer for things they don't have, with fake values, empty methods or errors.
- Interface segregation: split a big promise into small ones, so each class keeps only the promises it can.
- Each piece of code then asks for the smallest promise it needs: the lab report asks only for things with labs.
- Group methods by who uses them, and don't split so far that every method has a promise of its own.

**Before this:** *Interfaces: A Promise Any Class Can Keep*, and *Liskov Substitution: No Surprises from a Stand-In*.

Northside High's first course in the app was Chemistry, so the promise every course keeps was written with Chemistry in mind: attendance, a lab score and a final exam. This term the school added Art, which has attendance and nothing else. Art had to keep the whole promise anyway, so it answers 0 for labs and 0 for the final. Yesterday a parent called the office: why does the lab report say their daughter got a 0 in art?

## The symptom: fake answers on a real report

Here's the promise and the school's three reports:

```csharp
List<ICourse> courses = new List<ICourse> { new Chemistry(), new Art() };
Console.WriteLine("Attendance: " + string.Join(", ", courses.Select(c => c.Name + " " + c.Attendance() + "%")));
Console.WriteLine("Labs: " + string.Join(", ", courses.Select(c => c.Name + " " + c.LabScore())));
Console.WriteLine("Final exams: " + string.Join(", ", courses.Select(c => c.Name + " " + c.FinalExam())));

// One big promise: every course must answer all of it.
interface ICourse
{
    string Name { get; }
    int Attendance();
    int LabScore();
    int FinalExam();
}

class Chemistry : ICourse
{
    public string Name => "Chemistry";
    public int Attendance() => 98;
    public int LabScore() => 88;
    public int FinalExam() => 91;
}

class Art : ICourse
{
    public string Name => "Art";
    public int Attendance() => 95;
    public int LabScore() => 0;   // Art has no labs, but the promise says it must answer.
    public int FinalExam() => 0;  // No final exam either.
}
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88, Art 0
Final exams: Chemistry 91, Art 0
```

```java
// One big promise: every course must answer all of it.
interface Course {
    String name();
    int attendance();
    int labScore();
    int finalExam();
}

class Chemistry implements Course {
    public String name() { return "Chemistry"; }
    public int attendance() { return 98; }
    public int labScore() { return 88; }
    public int finalExam() { return 91; }
}

class Art implements Course {
    public String name() { return "Art"; }
    public int attendance() { return 95; }
    public int labScore() { return 0; }   // Art has no labs, but the promise says it must answer.
    public int finalExam() { return 0; }  // No final exam either.
}

void main() {
    List<Course> courses = List.of(new Chemistry(), new Art());
    List<String> attendance = new ArrayList<>();
    List<String> labs = new ArrayList<>();
    List<String> finals = new ArrayList<>();
    for (Course course : courses) {
        attendance.add(course.name() + " " + course.attendance() + "%");
        labs.add(course.name() + " " + course.labScore());
        finals.add(course.name() + " " + course.finalExam());
    }
    IO.println("Attendance: " + String.join(", ", attendance));
    IO.println("Labs: " + String.join(", ", labs));
    IO.println("Final exams: " + String.join(", ", finals));
}
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88, Art 0
Final exams: Chemistry 91, Art 0
```

```python
from abc import ABC, abstractmethod


class Course(ABC):
    """One big promise: every course must answer all of it."""

    @abstractmethod
    def attendance(self):
        ...

    @abstractmethod
    def lab_score(self):
        ...

    @abstractmethod
    def final_exam(self):
        ...


class Chemistry(Course):
    name = "Chemistry"

    def attendance(self):
        return 98

    def lab_score(self):
        return 88

    def final_exam(self):
        return 91


class Art(Course):
    name = "Art"

    def attendance(self):
        return 95

    def lab_score(self):
        return 0  # Art has no labs, but the promise says it must answer.

    def final_exam(self):
        return 0  # No final exam either.


courses = [Chemistry(), Art()]
print("Attendance: " + ", ".join(c.name + " " + str(c.attendance()) + "%" for c in courses))
print("Labs: " + ", ".join(c.name + " " + str(c.lab_score()) for c in courses))
print("Final exams: " + ", ".join(c.name + " " + str(c.final_exam()) for c in courses))
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88, Art 0
Final exams: Chemistry 91, Art 0
```

```javascript
// One big promise, in words: every course has a name, attendance(), labScore() and finalExam().
class Chemistry {
  name = "Chemistry";
  attendance() { return 98; }
  labScore() { return 88; }
  finalExam() { return 91; }
}

class Art {
  name = "Art";
  attendance() { return 95; }
  labScore() { return 0; }   // Art has no labs, but the promise says it must answer.
  finalExam() { return 0; }  // No final exam either.
}

const courses = [new Chemistry(), new Art()];
console.log("Attendance: " + courses.map((c) => c.name + " " + c.attendance() + "%").join(", "));
console.log("Labs: " + courses.map((c) => c.name + " " + c.labScore()).join(", "));
console.log("Final exams: " + courses.map((c) => c.name + " " + c.finalExam()).join(", "));
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88, Art 0
Final exams: Chemistry 91, Art 0
```

```typescript
// One big promise: every course must answer all of it.
interface Course {
  name: string;
  attendance(): number;
  labScore(): number;
  finalExam(): number;
}

class Chemistry implements Course {
  name = "Chemistry";
  attendance(): number { return 98; }
  labScore(): number { return 88; }
  finalExam(): number { return 91; }
}

class Art implements Course {
  name = "Art";
  attendance(): number { return 95; }
  labScore(): number { return 0; }   // Art has no labs, but the promise says it must answer.
  finalExam(): number { return 0; }  // No final exam either.
}

const courses: Course[] = [new Chemistry(), new Art()];
console.log("Attendance: " + courses.map((c) => c.name + " " + c.attendance() + "%").join(", "));
console.log("Labs: " + courses.map((c) => c.name + " " + c.labScore()).join(", "));
console.log("Final exams: " + courses.map((c) => c.name + " " + c.finalExam()).join(", "));
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88, Art 0
Final exams: Chemistry 91, Art 0
```

`Art 0` on the lab report reads like a failing grade. It's really "doesn't apply", dressed up as a number because the promise left Art no other way to answer.

- **The symptom:** a class keeps parts of a promise it can't really keep, with fake values (`0`), empty methods, or "not supported" errors (the broken stand-in from *Liskov Substitution*).
- **The cause:** one promise that bundles things only some classes have. Every class is forced to answer for all of it, and every report that uses part of it gets all of it.

## What would you try?

**Return -1 instead of 0, and have the reports skip it.** Now every report has to know the secret code, and the next report someone writes will print `Art -1`.

**Throw "Art has no labs" from `LabScore`.** That's the broken stand-in again: the lab report stops at Art, like the report card in the last lesson.

**Have each report check the course's name** (`if (c.Name == "Art") continue;`). The reports now know every course that lacks labs. Music arrives next term, and every report needs another check.

Each try leaves the big promise in place and works around it.

## The idea: small promises

A TV remote with 80 buttons is the everyday version: most people use power, volume and channel, and the other 77 buttons get in the way (and get pressed by accident). A small remote with the buttons you use is easier for everyone.

![A TV remote crowded with 80 tiny buttons, next to a small remote with only a power button, volume buttons and channel buttons](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/1f342b899a614af7b7e1279dee32ef3e.webp)

The **interface segregation principle** says: **split a big promise into small ones, so no class has to keep a promise it can't, and no code has to depend on methods it doesn't use.** *Segregation* here means separating. Every course has a name and attendance; only some have labs; only some have a final exam. That's three promises:

```csharp
Chemistry chemistry = new Chemistry();
Art art = new Art();
Console.WriteLine(AttendanceReport(new List<ICourse> { chemistry, art }));
Console.WriteLine(LabReport(new List<IHasLabs> { chemistry }));
Console.WriteLine(FinalExamReport(new List<IHasFinalExam> { chemistry }));

// Each report asks only for the promise it uses.
string AttendanceReport(List<ICourse> courses) => "Attendance: " + string.Join(", ", courses.Select(c => c.Name + " " + c.Attendance() + "%"));
string LabReport(List<IHasLabs> courses) => "Labs: " + string.Join(", ", courses.Select(c => c.Name + " " + c.LabScore()));
string FinalExamReport(List<IHasFinalExam> courses) => "Final exams: " + string.Join(", ", courses.Select(c => c.Name + " " + c.FinalExam()));

// Small promises: each course keeps only the ones it can.
interface ICourse
{
    string Name { get; }
    int Attendance();
}

interface IHasLabs : ICourse
{
    int LabScore();
}

interface IHasFinalExam : ICourse
{
    int FinalExam();
}

class Chemistry : IHasLabs, IHasFinalExam
{
    public string Name => "Chemistry";
    public int Attendance() => 98;
    public int LabScore() => 88;
    public int FinalExam() => 91;
}

class Art : ICourse
{
    public string Name => "Art";
    public int Attendance() => 95;
}
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88
Final exams: Chemistry 91
```

```java
// Small promises: each course keeps only the ones it can.
interface Course {
    String name();
    int attendance();
}

interface HasLabs extends Course {
    int labScore();
}

interface HasFinalExam extends Course {
    int finalExam();
}

class Chemistry implements HasLabs, HasFinalExam {
    public String name() { return "Chemistry"; }
    public int attendance() { return 98; }
    public int labScore() { return 88; }
    public int finalExam() { return 91; }
}

class Art implements Course {
    public String name() { return "Art"; }
    public int attendance() { return 95; }
}

// Each report asks only for the promise it uses.
String attendanceReport(List<Course> courses) {
    List<String> lines = new ArrayList<>();
    for (Course course : courses) { lines.add(course.name() + " " + course.attendance() + "%"); }
    return "Attendance: " + String.join(", ", lines);
}

String labReport(List<HasLabs> courses) {
    List<String> lines = new ArrayList<>();
    for (HasLabs course : courses) { lines.add(course.name() + " " + course.labScore()); }
    return "Labs: " + String.join(", ", lines);
}

String finalExamReport(List<HasFinalExam> courses) {
    List<String> lines = new ArrayList<>();
    for (HasFinalExam course : courses) { lines.add(course.name() + " " + course.finalExam()); }
    return "Final exams: " + String.join(", ", lines);
}

void main() {
    Chemistry chemistry = new Chemistry();
    Art art = new Art();
    IO.println(attendanceReport(List.of(chemistry, art)));
    IO.println(labReport(List.of(chemistry)));
    IO.println(finalExamReport(List.of(chemistry)));
}
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88
Final exams: Chemistry 91
```

```python
from abc import ABC, abstractmethod


class Course(ABC):
    """Every course: a name and attendance."""

    @abstractmethod
    def attendance(self):
        ...


class HasLabs(Course):
    """Only courses with labs keep this promise."""

    @abstractmethod
    def lab_score(self):
        ...


class HasFinalExam(Course):
    """Only courses with a final exam keep this promise."""

    @abstractmethod
    def final_exam(self):
        ...


class Chemistry(HasLabs, HasFinalExam):
    name = "Chemistry"

    def attendance(self):
        return 98

    def lab_score(self):
        return 88

    def final_exam(self):
        return 91


class Art(Course):
    name = "Art"

    def attendance(self):
        return 95


# Each report asks only for the promise it uses.
def attendance_report(courses):
    return "Attendance: " + ", ".join(c.name + " " + str(c.attendance()) + "%" for c in courses)


def lab_report(courses):
    return "Labs: " + ", ".join(c.name + " " + str(c.lab_score()) for c in courses)


def final_exam_report(courses):
    return "Final exams: " + ", ".join(c.name + " " + str(c.final_exam()) for c in courses)


chemistry = Chemistry()
art = Art()
print(attendance_report([chemistry, art]))
print(lab_report([chemistry]))
print(final_exam_report([chemistry]))
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88
Final exams: Chemistry 91
```

```javascript
// Small promises, in words: every course has a name and attendance();
// a course with labs also has labScore(); a course with a final exam also has finalExam().
class Chemistry {
  name = "Chemistry";
  attendance() { return 98; }
  labScore() { return 88; }
  finalExam() { return 91; }
}

class Art {
  name = "Art";
  attendance() { return 95; }
}

// Each report asks only for the promise it uses.
function attendanceReport(courses) {
  return "Attendance: " + courses.map((c) => c.name + " " + c.attendance() + "%").join(", ");
}

function labReport(courses) {
  return "Labs: " + courses.map((c) => c.name + " " + c.labScore()).join(", ");
}

function finalExamReport(courses) {
  return "Final exams: " + courses.map((c) => c.name + " " + c.finalExam()).join(", ");
}

const chemistry = new Chemistry();
const art = new Art();
console.log(attendanceReport([chemistry, art]));
console.log(labReport([chemistry]));
console.log(finalExamReport([chemistry]));
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88
Final exams: Chemistry 91
```

```typescript
// Small promises: each course keeps only the ones it can.
interface Course {
  name: string;
  attendance(): number;
}

interface HasLabs extends Course {
  labScore(): number;
}

interface HasFinalExam extends Course {
  finalExam(): number;
}

class Chemistry implements HasLabs, HasFinalExam {
  name = "Chemistry";
  attendance(): number { return 98; }
  labScore(): number { return 88; }
  finalExam(): number { return 91; }
}

class Art implements Course {
  name = "Art";
  attendance(): number { return 95; }
}

// Each report asks only for the promise it uses.
function attendanceReport(courses: Course[]): string {
  return "Attendance: " + courses.map((c) => c.name + " " + c.attendance() + "%").join(", ");
}

function labReport(courses: HasLabs[]): string {
  return "Labs: " + courses.map((c) => c.name + " " + c.labScore()).join(", ");
}

function finalExamReport(courses: HasFinalExam[]): string {
  return "Final exams: " + courses.map((c) => c.name + " " + c.finalExam()).join(", ");
}

const chemistry = new Chemistry();
const art = new Art();
console.log(attendanceReport([chemistry, art]));
console.log(labReport([chemistry]));
console.log(finalExamReport([chemistry]));
```

```text
Attendance: Chemistry 98%, Art 95%
Labs: Chemistry 88
Final exams: Chemistry 91
```

The attendance line is the same; the lab and final-exam reports no longer show a fake `Art 0`, because Art no longer claims to have labs or a final. And look at what the compiler now knows: in C#, Java and TypeScript, `LabReport(new List<IHasLabs> { art })` doesn't compile, since Art never promised a lab score. The mistake can't reach a parent's inbox.

**Try it.** Add a `Music` course with attendance 97 and a final exam of 85, and no labs. Which promises does it keep? Put it in the attendance and final-exam reports, and try to put it in the lab report to see what happens in your language.

**Where the languages differ.** In C#, Java and TypeScript the small promises are interfaces, and one promise can build on another (`IHasLabs : ICourse`, `extends`). Python writes them as abstract base classes, and `Chemistry(HasLabs, HasFinalExam)` keeps two at once. JavaScript has no interfaces, so nothing stops you from handing Art to the lab report; the small promises are still worth writing down, because they tell the next reader which courses belong where.

## In your textbook

The usual wording is **"no client should be forced to depend on methods it does not use"**: a *client* is any code that uses a class, like the lab report. Robert C. Martin wrote it down while working on a printer company's software, where one huge job class was used by every part of the system.

## When to bend it

- **When every class really does keep the whole promise,** a single interface is clearer. Don't split a promise that nobody fakes.
- **Don't give every method its own promise.** Group methods by who uses them: the lab report uses lab scores, so that's one promise, not one per method.
- **Splitting has a cost:** more names to learn. It pays off when classes are faking answers, or when code depends on far more than it uses.

## Check yourself

2 questions to try on the lesson page.

## So what

A promise should be small enough that every class keeping it can keep all of it. When a class starts answering with fake zeros or "not supported", split the promise, and let each piece of code ask only for what it uses.

## Key terms

- [Interface Segregation Principle](https://www.ask-codey.com/glossary/interface-segregation-principle)
- [Interface](https://www.ask-codey.com/glossary/interface-oop)

## Cheat sheets

- [Interface Segregation: Small Promises](https://www.ask-codey.com/cheat-sheets/dp-interface-segregation-cheat-sheet)

Source: https://www.ask-codey.com/lessons/dp-interface-segregation
