3

Interfaces 101 : Interface Design Considerations Ep. 7

 1 year ago
source link: https://www.ardanlabs.com/blog/2023/03/interfaces-101-interface-design-considerations.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Interfaces 101 : Interface Design Considerations Ep. 7

Author image

Ardan Labs

March 13, 2023
interfaces-07.jpg?v=1

Introduction

In episode 6, Miki built a logger package with the aim of making it as versatile as possible. To achieve this, he constructed his logger object with a function that would: accept the io.Writer interface as a parameter and perform type assertions to retrieve other interface types as needed. By building this, Miki demonstrated how polymorphism is achieved with Go by changing the type of a variable with type assertions.

In this video, Miki will shift his attention towards the theory side of programming and give a lecture on interface design. The first idea he’ll introduce is that interfaces state what need, not what we provide. To build on this idea, Miki will give a detailed overview of Go’s io.Copy function, its intended use and how the function states that it needs to have a variable to read from and another to write to. The next idea he’ll propose is if an interface has more than five functions, something may be wrong, which can be strongly correlated to the Go proverb the bigger the interface, the weaker the abstraction. Watch and learn more about Go interfaces and the design considerations to keep in mind when writing one.

Things you will learn in this video

  • Criteria to determine the effectiveness of an interface.
  • Quick overview of Go’s io.Reader and io.Writer interfaces.

Video


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK