Last active
January 2, 2020 08:40
-
-
Save J7mbo/788c4071e4c9dc1fa3c55a5d6854e31b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Service Package | |
type Service interface { | |
CountNumUsers() int | |
} | |
type service struct { | |
Repository *UserRepository | |
} | |
func (s service) CountNumUsers() int { | |
return s.Repository.Count() | |
} | |
func New(r UserRepository) Service { | |
return service{Repository: &r} | |
} | |
// Package 2 | |
r := Repository.New(db) | |
s := Service.New(*r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment