Folder structure by domain vs class type

Two different ways to organize your folders:

  • By class type

image

  • By domain

image

Yii application example uses the first type. I’m thinking the second alternative might put files together in a single folder that have tighter coupling. E.g. PostController has tight coupling with PostEntity, PostRepository, PostDTO, etc, not so much with CommentController.

Second alternative might be better to isolate change.

Thoughts?

Edit: Oh, you actually did this in the Yii example app. Great! yii-demo/src at master · yiisoft/yii-demo · GitHub

1 Like

That’s the way to go. The only thing is:

Cohesion, not coupling.

1 Like

Wait wait. Cohesion is a metric for a single class? And coupling a metric for how two classes interact? Or did I get that wrong?

Yes, you did. Both metrics are for a module(s) which is multiple classes.

Well, there are cohesive metric for classes, too. LCOM, for example: Project Metrics Help - Cohesion metrics

Well, yes. You can measure cohesion of methods as well.