From OOP to Go
summary
Starting from a literal Java→Go translation, a logger built with embedded structs unexpectedly keeps calling the inner logger and prints to stdout instead of a file; the naive inheritance-like override fails at runtime. Fixes use interfaces and dependency injection: implement a logging target, then swap to the standard library io.Writer (notably implemented by 351 types), or embed an interface in a logger struct to compose behavior. The interface-based designs work; the inheritance-like approach does not.
AI-written summary · about
chapters (9)
- 0:00Start
- 4:24What Is Oop
- 5:00Inheritance
- 8:34Embedded Structs
- 10:48Embedding Structs
- 13:14Practical Solution
- 15:41The Writer Interface
- 17:39Embedding an Interface Instead of Embedding a Struct
- 18:41Logger Struct
related talks
33mClean Up Your GOOOP: How to Break OOP Muscle Memory
33mClean Up Your GOOOP: How to Break OOP Muscle Memory
05mComposition Over Inheritance
46mStructured Logging for the Standard Library
26mA Fast Structured Logging Package
20mStructured Logging for the Standard Library
52mGo Go Java Developer
33mIs Go Object-Oriented? A Case of Public Opinion
