3

This one's all over our codebase but I'm not sure I've ever heard a name put to it.

We have C# and Java (and Rails but we don't have to touch it very often) so I'll speak more generally. It's like the data concerns never get fully established until you're literally right in a view controller preparing to drop it on the page (note: we're way past the actual SQL queries in most cases here).

For instance, we have data for a certain product type coming in from CRMs, from scans done with our mobile app, and pulled up from inventory in DBs and yet somehow it's not until we get to the spot where we're literally about to drop it on the page that we suddenly discover that there's business logic to attend to. Our actions and view controllers are GIGANTIC. We're asking all kinds of questions of every object and branching on them, whether it isThis or hasThat, data sources, customer preferences and sometimes stuff so seemingly arbitrary it might as well be phase of the moon, migration habits of species I've never even heard of, most-googled film stars...

And it doesn't always stop at the controller. The Java in particular is notorious for letting it all spill out into the JSP and then even onto the client-side in the JS.

This phenomenon has to have a name, but I've never heard it. What is it?

8
  • 11
    Very generally, it's called Lazy Evaluation. If you never drop it on the page, you never have to sort it. It's a tradeoff, not an anti-pattern. Jul 12, 2013 at 0:30
  • I fail to see the problem unless you are trying to re-sort already sorted data and use a sorting algorithm that does not have best cast O(n) time, but even still... Jul 12, 2013 at 0:39
  • 1
    @ThomasEding The way I read the question, problem is the sort operation has to do a lot of additional (business logic) queries in order to find out the proper sort order. This then bloats the controller with all sorts of business logic analysis stuff - if the sort was done at the model end before passing to the controller, it remain in the place where all the other business logic it. Jul 12, 2013 at 9:20
  • 1
    I am not sure of this having a name but am very familiar with it. You tend to see this happen when teams are split by expertise in application layers and requirements are incomplete (Eg. Database team, Middle-Tier guys, Front-End guys...) The "Front-End guys" and users eventually realize missing functionality that is needed or discover unanticipated complexity, leading to the easier path of mingling business logic with the presentation logic of your controller.
    – maple_shaft
    Jul 12, 2013 at 11:00
  • 1
    @maple_shaft +1 for the first half of that but for the record I AM the front end guy but pinch-hitting as a generalist. I don't want this garbage in my layer or any one single layer. Any time you're firing an is or has method IMO, you're failing to realize that the thing you're asking is the thing that should be structuring/packaging the data for you since it knows what you need. Trying to do anything non-trivial in JavaScript would be impossible doing things this way. If this sort of thing in the JSP doesn't piss off your front end dev, get a new one. Jul 12, 2013 at 14:15

1 Answer 1

4

Craig Larman calls it "The Bloated Controller" in Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development

Poorly designed, a controller class will have low cohesion - unfocused and handling too many areas of resposibility; this is called a bloated controller. Signs of bloating include:

(...)

  • The controller itself performs many of the tasks necessary to fulfill the system event, without delegating the work. This usually involves a violation of Information Expert and High Cohesion.

(...)

4
  • Never heard of "the bloated controller," but the principle is sound. The Controller is basically a switch-yard, a go-between the Model and the View. There shouldn't be any more functionality in it than that. That said, "bloated controller" doesn't seem to adequately convey what the OP describes. Jul 12, 2013 at 4:33
  • Never heard of Craig Larman... Guess everyone has their one name for everything.
    – Den
    Jul 12, 2013 at 8:04
  • That's pretty in line with the problem. I probably should have stressed a more general system-wide problem where each layer is juggling things that should have been established by the last one, but I'll take that if nobody else has anything since it definitely is most noticeable in the controller-type constructs. Jul 12, 2013 at 14:55
  • That's as close to an established name as we're going to get I guess. I still thought the metaphor of stepping out of the house with a bag of random clothes and getting dressed by picking out things one at a time until you get to the ones you need for wherever your going worked as a metaphor but there's no short and sweet way to describe that. (somebody edited that out of the original post) :P Jul 17, 2013 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.