views:

131

answers:

3

I'm making a Perl website, and I'll using Template Toolkit (for the view), a whole bunch of objects for DB interaction and business logic (the model), but I'm wondering: should the controllers be OO?

I feel like they should, just for consistency, but it also feels it might be a bit redundant when I'm not interacting with the controllers in an OO way. The controllers are called more in a fire-and-forget kind of way.

Thanks for any thoughts.

+2  A: 

In my opinion, if it feels reduntant, you shouldn't use it.

OOP can have more cons than pros if you use it on a project that doesn't need it.

If it's just about consistency just drop it. there's plenty of people that (for example) in c++ use stl but write the rest of the code in a procedural way. If you feel OOP overwhelming go for the mixed approach you are thinking of using (OOP where needed, procedura the rest), as long as your code doesn't become difficult to read because of this.

klez
+2  A: 

Yes, make the controllers object-oriented. You should be interacting with them as objects. You might want to extend or modify them later with subclasses. A lot of people get themselves into trouble by assuming that they'll ever only need one controller, so they paint themselves into a corner by not planning for future flexibility.

brian d foy
I'm not totally sure I agree with this. I'm a huge fan of YAGNI. You can always change it later. Sure this means updating a lot of calling code but that's what we do isn't it? I'm not sure limiting the work of a possible refactoring or our code should be a design goal.
Jeremy Wall
This isn't a feature, so YAGNI doesn't apply. It's just as much work to do it one way or the other. You might as well do it in the way that has more flexibility. But, do what you like if you think you have perfect knowledge of the future. My experience is that no one likes the previous design and is always trying to shoehorn something into it.
brian d foy
+2  A: 

You need to look at Catalyst, which will save you a good deal of worry about what OO to use for controllers and how to implement it. It's not perfect but, if you like, it's a well beaten path through the design wilderness.

ijw
Thanks for the pointer - I'll be looking into this
aidan