-
Notifications
You must be signed in to change notification settings - Fork 0
プロジェクトのファイル構成を修正 #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
プロジェクトのファイル構成を修正 #58
Conversation
[ディレクトリの命名や構成に関して] |
case int(entity.WrapServer): | ||
gi = gateway.NewGrpcServeGateway() | ||
default: | ||
gi = gateway.NewGrpcServeGateway() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンストラクタ関数 (New〇〇~)はcmdとかのエントリポイントで呼んで欲しい
色々なところで呼び出したらレイアードアーキテクチャの意味がなくなりそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自分の中のレイヤードアーキテクチャーの目的は、プログラムの責務の分離だけどそれで同じですかね?
この変更の意図は、APIの接続先を選択するロジックを、コマンドの表示周りの処理と分離すること。
cmdディレクトリはCUIの表示とか、操作とかに関する処理だけにとどめたい。どのAPIにアクセスするかの選択は表示とかとは無関係で、cmdディレクトリ内のプログラムでは面倒を見ないようにしたい。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンストラクタ関数は一箇所にまとめて保守性をあげたかったのが目的。
構造体の中に、該当のサービスを入れたら済む話なのかなと思った。
レイヤードアーキテクチャの目的は文脈
次第だと思うけど、リファクタしても影響範囲を出にくくするのと可読性を上げる事だと思う。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
保守性を上げることは、処理をまとめて同じところに書くよりも、各プログラムの責務を明確に分けることで生まれると僕は思うけど。
CLI上での表示をいじりたければ全てcmd\suggest.go
を見る。万が一他の部分を変えたとしても、表示以外に影響を及ぼさない。中の処理を変えたければinternal\service\suggest_cmd.go
を見る。というのが保守性を高めることじゃないですかね?
「リファクタしても影響範囲を出にくくするのと可読性を上げる事」は、全てのアーキテクチャが考えられている目的で、中でもレイヤードアーキテクチャの目的は、レイヤごとに責務を分けて、他のレイヤの役割を混ぜないことじゃないですかね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンストラクタ関数をエントリポイントでまとめた方が依存関係が全部わかって保守性が上がるって意味でいいたかった。
今回は、cmdが実質インターフェースだから特殊だけど。
そこはNewContainerとかでDIだけ別パッケージに切り出すとかで対処できそうかも。
コンストラクタ関数をまとめるのは、まとめるのが目的でなくコード規約てきなものだとイメージしてた。
レイヤ責務を分ける目的はどんな事だと考えてる?
} | ||
|
||
func (ps fileDiffService) CreateFileDiffStr() (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この関数は他のUsecase (分割コミットとか)で使って共通化するから
上層のDomain Seriviceに移行したほうがいいかな
(共通化するタイミングで大丈夫なのかなとも思いつつ)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これ、変数名とかを変えただけだよ。
基本domain serviceはusecaseより下層かと思うけど、上層に移行というのは何を想定してた?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかに、下層だな。すまん
クリーンアーキテクチャの図を想像していい間違えた。
return err | ||
} | ||
|
||
switch configIndex { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
マジックナンバーはハードコーディングしないで
iotaとかでenum化した方が見やすいかも
これは変更します。
変更しても良いけど、ここはservice(明示的に書くならapplication service)ではないので、するならしたのと併せて
ごめんこれが何を言いたいのかよく理解できていないわ。 あと、domainService作るならentity層の中かと思うよ。 |
クリーンアーキの文脈でたしかにgatewayはrepositoryと言われることはあるからgatewayでない方がいいかもね。 entityの中にserviceを入れるのはどこがソースだろ?そうした方がいい理由は何だと思う? domainにまとめたかったのは、そこに具体的な実装がないつまり、そこを上位のレイヤーだと示したいだけで、無駄に層を深くするのはやる必要はないと思う。 仮にgatewayがrepositoryなら、そこに具体的な実装を置くのはどうだと思う? repositoryはdbアクセスを抽象化する文脈で使われるからクライアント側で使うのは微妙かも。 |
概要
実装
/cmd
=>/service
=>/gateway
=>entity