Hacker News new | ask | show | jobs
by secstate 4518 days ago
Ah, but there be monsters in that sea too. I used to subscribe to the many-focused-models camp, but depending on the relationships you're trying to model, that can become damn-near unmaintainable as well.

I've actually begun building out more "wide" models, that is, models with a great many fields set to allow null/blank, because mixins and abstract base classes are very hard to maintain 3-4 years out. Don't misunderstand me, there's a place for those, but it's easy to get lost on road to abstraction.

Of course, the lesson is that if you're representing complex relationships in code, the implementation is going to wind up complex to some extent.

1 comments

There's another option besides mixins and base classes, composition. You can break your fat model into lots of smaller classes that you aggregate into your original model. The big advantage over using mixins is that the scope is kept much smaller. Keeping scopes small in general is always a good way to scale up to a large codebase (functional languages get this pretty much for free).
Yes, I generally stick to composition. "High level" classes end up using a bunch helper classes to perform specialized tasks. I find that I do not often find the need for an abstract base class or mixins, but I will use them if it makes sense.