bxcodec / go-clean-arch

Go (Golang) Clean Architecture based on Reading Uncle Bob's Clean Architecture
MIT License
9.03k stars 1.19k forks source link

Question: Should we use a pointer as a return type of NewUsecase, NewRepository? #57

Closed aeharvlee closed 3 years ago

aeharvlee commented 3 years ago

In this repo, there are building functios like below(NewUsecase or NewRepository)

type mysqlArticleRepository struct {
    Conn *sql.DB
}

// NewMysqlArticleRepository will create an object that represent the article.Repository interface
func NewMysqlArticleRepository(Conn *sql.DB) domain.ArticleRepository {
    return &mysqlArticleRepository{Conn}
}

As you can see, it returns address using &mysqlArticleRepository which of data type is a pointer. So I think return type should be pointer *domain.ArticleRepository like below

type mysqlArticleRepository struct {
    Conn *sql.DB
}

// NewMysqlArticleRepository will create an object that represent the article.Repository interface
func NewMysqlArticleRepository(Conn *sql.DB) *domain.ArticleRepository {
    return &mysqlArticleRepository{Conn}
}

I want to hear what you guys think about this. Thanks for reading this issue. 😄

ghostiam commented 3 years ago

domain.ArticleRepository is interface, interface cannot be pointer.

aeharvlee commented 3 years ago

@ghostiam Thanks for your feedback. 👍

frederikhors commented 3 years ago

I think you can close this issue now.