Intermediate - LogeshVel/go_programs GitHub Wiki
Functions














Since Slice is already a pointer to an array. SO just passing the value of slice we could change the original values of the slice.
For, Slice and Map we can alter the values just by passing the values. For Slice and map there is no need to pass by reference.

Function as variables, arguments...











Here we have i initial value as 0 that have been used in the return function. So Go keeps that value. so whenever the returned fucntion is called that value is incremented. In the print statement we could see that the used print so no new line character.
Object Orientation
Classes and Objects
Golang is an object orientation language. Maybe it doesn't have the class but it achieves the OOPS in a different way.



Encapsulation

Go has no class


We cannot use the built in types as the receiver types.


Structs






If the receiver type in the method is not a pointer then the entire value is copied in the method call.

Pointer Receivers

no dereference is needed

no reference is needed



But we could make the method with the receiver type as that struct so that the method is associated with that struct.


Polymorphsim

No inheritance in Golang


Interfaces




Concrete type vs Interface type





Nil dynamic value

Nil dynamic type

Empty Interface

Type Assertion

Type Switch
A type switch compares types rather than values.
While working with the empty interface, the type of empty interface may change at the run time. As we know empty interface can hold value of any type. So, before performing any operation with the empty interface we need to type assert it.
We can use Type switch for type asserting and perform some operations.

Error Interface

