Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

interfaces-go

Interfaces

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Interfaces: the syntax, patterns, and safety habits you need before advancing in Go.

Implicit interfaces enable small, testable packages—composition over inheritance is idiomatic Go.

You will apply Interfaces in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Go interfaces are implicit—no implements keyword like Java. A type satisfies an interface by having the required methods.

Defining and using interfaces

type Stringer interface {
    String() string
}

The empty interface interface{} (alias any since Go 1.18) accepts any type—use sparingly; prefer generics or concrete types.

Interface values

An interface value holds a dynamic type and dynamic value. Type assertions v.(T) extract concrete types; the comma-ok form handles failures safely.

Important interview questions and answers

  1. Q: Implicit vs explicit interfaces?
    A: Go uses implicit satisfaction—decouples packages and enables small, focused interfaces.
  2. Q: nil interface gotcha?
    A: An interface is nil only if both type and value are nil—a typed nil pointer inside an interface is not nil.

Self-check

  1. How does a type satisfy an interface?
  2. What does the comma-ok type assertion do?

Tip: Keep interfaces small—io.Reader has one method; define interfaces at the consumer, not the implementer.

Interview prep

Explicit implements?

No—types satisfy interfaces implicitly by having required methods.

Nil interface gotcha?

Interface is nil only when both type and value are nil—a typed nil pointer inside an interface is not nil.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Implicit satisfy?
  • Empty interface?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump