<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Interfaces on BradCypert.com</title>
    <link>https://www.bradcypert.com/tags/interfaces/</link>
    <description>Recent content in Interfaces on BradCypert.com</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 27 Dec 2022 16:51:00 -0500</lastBuildDate>
    <atom:link href="https://www.bradcypert.com/tags/interfaces/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How Golang Interfaces Work</title>
      <link>https://www.bradcypert.com/how-golang-interfaces-work/</link>
      <pubDate>Mon, 08 Jul 2019 00:00:00 +0000</pubDate>
      <guid>https://www.bradcypert.com/how-golang-interfaces-work/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://gobyexample.com/interfaces&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Interfaces&lt;/a&gt;&#xA; are a tool that allows you to define the behavior of objects and in Golang, interfaces are no different (except that they work on structs instead of “objects”). However, Go has some strange features for interfaces that users from other languages might not expect.&lt;/p&gt;&#xA;&lt;p&gt;Let’s take it slow and start by defining an interface in Go:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;type&lt;/span&gt; Sandwich &lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;interface&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#50fa7b&#34;&gt;BeEaten&lt;/span&gt;()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#50fa7b&#34;&gt;CountPickles&lt;/span&gt;()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This fairly simple interface defines what a sandwich is capable of. Not what it looks like, not how it’s composed, but for the purposes of our application it’s all that we need to constitute a sandwich. This allows us to create things that ideally represent an actual sandwich (based on what a sandwich can and cannot do), but will also allow us to create strange amalgamations that aren’t actually sandwiches but can act as a sandwich. Confusing? Let’s distill that idea.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
