Golang Object-Oriented Programming
Everything you wanted to know about structs in Golang
This article is focused on working with object-oriented architecture in Golang. We don’t have classes in Golang, so the only way to support the object-oriented model is to work with structs.
Creating Structs in Golang
Structs can be used to represent a complex object comprising multiple key-value pairs.
Let's look for a scenario: We want to represent an employee in our organization. In order to represent an employee, we require a combination of key-value pairs containing all of the the employee-related data. The employee entity can be comprised of multiple keys/properties, such as Name
, Age
, Designation
, and Salary
. All of these attributes/properties collectively represent a single employee in our organization.
Let's create a simple Employee
dtruct with basic data properties.
The above code contains the following building blocks:
- The
type
keyword can be used to…