So, I started learning about design patterns. In particular, I spent a lot of time reading through this site [1] and "Head First Design Patterns".
It was a mistake.
I've used maybe 2-3 of these design patterns when actually writing code, and never because I intended to use, say, a factory or a singleton -- I wrote what code I thought was most appropriate and it turned out to match an existing pattern.
--
Here's what's more valuable to learn:
- SOLID principles
- Realizing that what depends on what in your web application matters.
You want your business logic depending on your DB access code and your web layer depending on your business logic.
You do NOT want your business logic depending on your web layer.
- Realizing that your web app is really just some business logic which has a HTTP interface.
- Organizing software into layers. In a web app you'd have layers for middleware, controllers, business logic, and database access.
- Folder structure. I have a folder for each layer and try to have a descriptive name for each file in it. If a folder is getting messy, add another folder inside it with a descriptive name.
- Understand that refactoring is a fact of life. When you start a project, there's no way you can think of the optimal design up-front. This means you'll write code, accrue technical debt, and will need to refactor. Realize that this is 100% normal.