Skip to Content
Learning Functional Programming in Go
book

Learning Functional Programming in Go

by Lex Sheehan
November 2017
Intermediate to advanced
670 pages
17h 35m
English
Packt Publishing
Content preview from Learning Functional Programming in Go

Interface segregation principle

It is better to have a lot of single purpose-specific interfaces than one general purpose interface. Our APIs should not accept references to structures that it does not need, and conversely, our client implementations should not depend on code that it does not use.

We'll see this soon in our Viva La Duck code example in the form of separate EatBehavior and StrokeBehavior interfaces.

When we strictly apply  the integration segregation principle we end up with interfaces with a single method. Such objects represent data with behavior, but it can also be modeled as behavior with data, which is what closures are in FP.

This is another area where it would be nice if Go supported Generics. Why create boiler plate ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781787281394Supplemental Content