なんのために構造体を定義するのか、なんのためにインターフェースにするのか、 なにを達成したかったのか。
設計とはなにか。
// 問題 //
package infrastructure
type RepositoryImpl struct {
// ??
}
var _ domain.Repository = (*RepositoryImpl)(nil)
func (r *RepositoryImpl) Content(context.Context) (*domain.Content, error) {}
// 1. sdkに直接依存
type RepositoryImpl struct {
s3Client *s3.Client
bucketName string
}
// 2. sdkラッパー実装に依存
type RepositoryImpl struct {
s3Client *MyS3Client
}
// 3. sdkラッパーの抽象に依存
type RepositoryImpl struct {
s3Client MyS3ClientInterface
}
// 4. ストレージの抽象に依存
type RepositoryImpl struct {
storage StorageClientInterface
}