
Delegation Over Inheritance
This article was originally published on bmf-tech.com . Introduction Object-oriented programming (OOP) is a way of thinking about "representing real-world objects in programs." However, directly bringing real-world classifications and definitions into programs can lead to unexpected breakdowns. In this article, we will explain three important concepts through the specific example of "Rectangle and Square." Duck Typing - Determining types by behavior, not by name Liskov Substitution Principle (LSP) - Ensuring behavioral compatibility Delegation Over Inheritance - Achieving robust design Duck Typing - Types Determined by Behavior "Duck typing" is a type concept based on the following philosophical metaphor. "If it quacks like a duck and walks like a duck, then it is a duck." This means determining types not by "type name" or "inheritance relationship," but by how the object behaves. Duck Typing in Go The Go language naturally realizes this concept despite being statically typed. As long
Continue reading on Dev.to
Opens in a new tab


