Skip to content

Commit

Permalink
[INTERFACES] constructor fucntion and shothand implementation glue
Browse files Browse the repository at this point in the history
  • Loading branch information
PatAkil committed Nov 1, 2024
1 parent eaa540b commit a6a7fbb
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion go-training.slide
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,34 @@ Empty interface in the past:

- Used by standard json and xml packages to (un) serialize

#----------------------------------------------
* Constructor function

type DataStorer interface {
...
}

type PatientDatastore struct {}

func New() DataStorer {
return &PatientDatastore{}
}

TIP: Write the constructor function first and let your IDE do the rest!

Use a pointer if the struct is large, or you want to modify the state

Implementation without constructor function:

type Service interface {
...
}
var _ Service = (*MockDeviceService)(nil)

type MockDeviceService struct {}



#----------------------------------------------

* Exercise: interfaces
Expand All @@ -931,7 +959,6 @@ Tasks:
Remove(key string) error
}

TIP: Create a constructor function and let your IDE do the magic
TIP: Use a map as in-memory datastore

Peek: examples/interfaces
Expand Down

0 comments on commit a6a7fbb

Please sign in to comment.