RE: [coldbox:15241] Rewriting an old Coldbox Model

In theory, your model should be mostly agnostic to what framework you’re using. The only interaction my model has with my framework are the places I use LogBox or WireBox. I think that is the reason that most framework tutorials don’t get into what you should be doing in your models that much. Your model should be the life-blood of your application though, so don’t be turned off by more model code than controller code. The controller (or handler as we call it in CB) it just a traffic cop that directs the flow of your app and tags the appropriate models to handle the event that’s being executed. My rule of thumb, is that my app should be able to accomplish any task with model code only. (Create an order, add an item a cart, send an E-mail, enroll in a course, etc) The handlers just organize what views are being used, what incoming variables the user is sending, and what service methods should be called to do the actual processing.

The example bean you posted it actually fairly anemic since it’s mostly just getters and setters. The gateway ironically has more business logic in it than the bean, and it’s really more of an DAO, but that’s mostly semantics.

If you’re looking to upgrade to a newer version of ColdBox, the only issue I can see is that your models are using the old “_wireme” attribute and would need to be updated to the new “inject” attribute.

In the frameworks that I have used there was little to no code necessary in a Model…”
I’d say that’s more a design decision by whomever made those apps. I don’t know of any CF frameworks that try to limit the amount of code in your models.

“…with the coldbox application I inherited there are literally hundreds of lines of code and multiple files for a single Model
A few hundred lines of code really isn’t that big of a deal if your model is responsible for a lot of work. Can you clarify what you mean by multiple files for a single model? Are you talking about having a FoobarService, FoobarBean, and FoobarDAO, etc?

Most importantly, there are many ways to build an app and I don’t want you thinking that you need to completely rewrite a perfectly good app (read: working, manageable, and making money) just because it doesn’t look like the best practices you hear people talking about. Can you you help us by clarifying exactly what you’re wanting to accomplish by rewriting your models?



ColdBox Platform Evangelist
Ortus Solutions, Corp

ColdBox Platform: