2 Embedding types



2 Embedding types

2   Embedding types

Please find the source code at https://github.com/SivaprasadTamatam/Golang-Course/tree/main/7-AdvancedGoFeatures/2%20-Embedded%20Types

Embedding types

In Go, there are several types of embeddings that can be used to extend the functionality of a struct or interface.

Here are some examples of embedding types in Go:

Struct embedding: Struct embedding is the process of including one struct type inside another struct type. This is a way to compose a new struct from existing ones.

Pointer embedding: Pointer embedding is a technique for embedding a type as a pointer instead of as a value. This is useful when you want to modify the embedded type in place.

Interface embedding: Interface embedding is similar to struct embedding, but it is used with interfaces. This is a way to combine the behavior of multiple interfaces into a single interface

Anonymous embedding: Anonymous embedding is a shorthand syntax for struct and interface embedding. Instead of explicitly naming the embedded type, you can use an anonymous field