{
  "id": 21818621,
  "title": "Learning Go as a Ruby Developer #8: Go Interfaces Are Basically Formal Duck Typing",
  "url": "https://urgent.news/2026/11/25/learning-go-as-a-ruby-developer-8-go-interfaces-are-basically-formal",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-25T16:29:14.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/shroukabozeid/learning-go-as-a-ruby-developer-8-go-interfaces-are-basically-formal-duck-typing-42c6"
  },
  "original_language": "en",
  "account": "As someone who has worked with Ruby, the concept of interfaces in Go was intriguing. In Ruby, we often employ what's known as \"duck typing,\" where the type or class of an object is less important than the methods it can perform. Go's interfaces, however, require a concrete type to implement all the methods defined in the interface.\n\nAn interface in Go is essentially a contract that specifies a set of methods a type must implement to satisfy the interface. It doesn't implement those methods itself; it merely declares the methods that any type claiming to fulfill the interface must possess. For instance, we can define an interface called Shape with a method called Area() that returns a float64. The concrete types implementing this interface, such as Square and Circle, are not obligated to define how the Area() method is calculated; that is the responsibility of the implementing type.\n\nInterestingly, there's no need to explicitly declare that a type implements an interface in Go. If a type has all the methods required by an interface, it implicitly satisfies that interface. This contrasts with Ruby, where we define an interface upfront and ensure that classes implement it.\n\nOnce we have an interface, we can use it to write flexible, behavior-focused code. For example, we can create a function that accepts a Shape as an argument and call it with either a Square or a Circle without needing to know their concrete types. This decouples the function from knowing about the specific types, allowing us to write more generic and reusable code.\n\nInterfaces can also be assigned to variables, which can hold different concrete types as long as those types satisfy the interface. This provides flexibility in changing the underlying type without altering the code that uses the interface.\n\nIn an example from my notes, an interface called Shaper was introduced with two methods: Area() and Volume(). A Square type was defined with an Area() method but lacked the Volume() method, thus not satisfying the Shaper interface. This shows that an interface must be fully implemented; partial implementations are not accepted.\n\nComparing this to Ruby, we see a similar scenario where we might simply rely on duck typing. We define classes like Square and Circle and implement an area method for each. Then, we can write a function that takes an object with an area method, regardless of its class, demonstrating Ruby's implicit reliance on the object's ability to fulfill the required behavior.",
  "summary": "Coming from Ruby, interfaces were an interesting concept because they reminded me of something we already do all the time: duck typing . Go doesn't have inheritance like traditional OOP languages, but it has interfaces that allow different types to be used through the same behavior. Let's see how that works. What Is an Interface? An interface defines a set of methods that a type must have to…",
  "key_points": [
    "Go interfaces define a contract of required methods for a type to satisfy.",
    "Interface implementation is implicit in Go; types must have all interface methods.",
    "Interfaces enable flexible, behavior-focused code with decoupled functions."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}