[Question] About pointers
dlopezby93 opened this issue · comments
Hi guys, I was checking the code and a question came up:
in product_service.go this function returns a pointer to the ProductService struct
func NewProductService(
productRepository repositories.ProductRepository,
sellerRepository repositories.SellerRepository,
) *ProductService {
return &ProductService{productRepository: productRepository, sellerRepository: sellerRepository}
}
but in infrastructure layer product_repository.go this function returns a ProductRepository
interface and the method returns a pointer to the concret implementation: GormProductRepository
.
func NewGormProductRepository(db *gorm.DB) repositories.ProductRepository {
return &GormProductRepository{db: db}
}
From my point of view the NewProductService function should return the interface type to ensure that the consumer has access only to the public methods defined by the interface.
I would like to know the difference between these cases, thank you very much.
Hi @dlopezby93, good catch! I think you are right and I have fixed it here: 99d254d
Thanks @sklinkert!