Last active
May 30, 2018 16:07
-
-
Save Adzz/5480d1bef39f2f2fb0e61e96b6ae302f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defprotocol Perimeter do | |
def calculate(shape) | |
end | |
defimpl Perimeter, for: Square do | |
def calculate(square) do | |
square.side * 4 | |
end | |
end | |
defimpl Perimeter, for: Circle do | |
def calculate(circle) | |
circle.radius * 2 * 3.14 | |
end | |
end | |
Perimeter.calculate(%Circle{radius: 10}) | |
Perimeter.calculate(%Square{side: 10}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment