Day 15 of #30DaysOfCode | FizzBuzz and Interfaces In Go
Tags: challenge, motivation, go, codenewbie
Published: 2020-07-12 17:26:36

Hey YOU! How are you doing today? I hope that you are having a fantastic day. I myself am having an amazing day. Today is the Day 15 of #30DaysOfCode challenge and it means that I have completed 50% of the challenge which is really cool. For this special day, I decided to dive into interfaces in Go. So, let's talk about that for a bit and then we will look into the example of fizzbuzz coding solution.

Interfaces are really amazing. It helps you to implement polymorphism in Go. As you know that Go is not an object-oriented programming language and as a result, we don't have classes and objects in Go. But we still need to write maintainable and scalable software and the Interfaces allows us to do so. So, <b>What is Interface?</b>

<h3>What is Interface?</h3>
An interface is a collection of method signatures that a Type can implement. Hence interface defines the behaviour of the object of the type which implements its method signature.
This is the technical definition of Interfaces. And today, I don't understand it fully. I still need to learn more about it to be able to share with somebody. So, I am going to leave the interfaces for today and hopefully, I will have enough understanding to share about it tomorrow.

Now, let's talk about the fizzbuzz coding challenge. What is it and then I will take a look at the solution. Basically, Its a programming task where if the number is divisible by 3 and 5 both then you have to return 'fizzbuzz', if the number is divisible by 3 only then you have to return 'fizz', if the number is divisible by 5 only then you have to return 'buzz' and if the number is not divisible by 3 or 5 then you have to return none. I don't know if this is actually the real task but this is the task which I know of. So the solution will be for this specific task and not the ones which are floating around the internet.

Now, let's take a look at the code and try to understand it. I won't go over each line because the code is self explanatory.

![fizzbuzz coding challenge in golang](https://dev-to-uploads.s3.amazonaws.com/i/9o3ywr9ys1cosvr4m71q.png)

Here we have defined a function which takes a number as a parameter and then we are checking for each of the cases using the conditionals. In the first <code>if</code> conditional, we are checking if the number is divisible by 3 and 4 both and if the number is then we are returning 'fizzbuzz'. In the second <code>else if</code> conditional, we are checking if the number is divisible by 3 and if it is then we will return 'fizz'. In the third <code>else if</code> conditional, we are checking if the number is divisible by 5 and if it is then we are returning 'buzz'. And if none of the cases is true then we will return 'none'.

Alright! That was all about interfaces and fizzbuzz coding challenge and I hope that you loved it. If you loved it, please don't forget to follow me here.



Connect With Me:
Youtube: <a href="https://www.youtube.com/c/ShubhamSauravYT" target="_blank" rel="noopener noreferrer">ShubhamSauravYT</a>.
Twitter: <a href="https://www.twitter.com/hiShubhamSaurav" target="_blank" rel="noopener noreferrer">@hiShubhamSaurav</a>
Instagram: <a href="https://www.instagram.com/hiShubhamSaurav" target="_blank" rel="noopener noreferrer">@hiShubhamSaurav</a>
Facebook: <a href="https://facebook.com/hiShubhamSaurav" target="_blank" rel="noopener noreferrer">@hiShubhamSaurav</a>