tags:

views:

192

answers:

4

if i've got a thread model and controller.

should that be in singular or plural for both the model and controller?

i could show a thread and also list threads.

dont know what i should use.

$thread->get_lists(); // doesnt sound good
$threads->show(); // doesnt sound good
+5  A: 

It doesn't matter.

I personally use singular for models and plural for controllers.

What matters, however, is that you pick a scheme and be consistent.

hobodave
+1 and thanks for bundle-phu :)
Gordon
@Gordon: ha, thank you. Where'd you hear about it?
hobodave
@hobodave Can't remember. Either via Twitter or stumbled upon it when I was searching for an all in one solution to minify CSS and JS.
Gordon
+1  A: 

KohanaPHP handles their singular/plural MVC components very well. I would check it out for reference as it makes sense. But when it comes down to it, it really doesn't matter and it depends on the programmer. I mean, if you are getting a bunch of lists, do get_lists() or if your getting contents of a list use get_list().

Jon
+1  A: 

Like the others said, it doesn't matter.

Concerning models, I like to use singular when the class represents a single row, e.g. when using Active Record or Table Row Gateway and plural when working with classes representing tables and recordsets, simply because I could make these return or contain classes with singular names and I could distinguish between them. But then again, I could just as well name them UserTable, UserCollection and User. Use what best represents your domain.

Some frameworks have a convention for naming models and controllers to work some automagic. For instance, the singular models will be inflected to use plural tables by default, so you do not have to map it yourself. This is called convention over configuration; over, because usually you can still configure it as you see fit.

The only time when I'd say it doesn't matter how you name your models and controller is when a code convention in use.

Gordon
A: 

That depends on the model. If objects of that class represent exactly one thing, use singular, if they represent many things, use plural (but you usually do not need such a class, use an array/a collection). Both cannot happen or you should redesign (1).

I'll use your Thread example:

If every object models one thread, name the class "Thread". If it models several threads at once, call it "Threads" (or "ThreadCollection" or the like).

(1) If you need both, a representation of a single thread and a representation of many threads at once, use two distinct classes (Thread and Threads) or create an array or a collection for the latter. Then you'll have it clean: $thread->show(); $threads->list();

GodsBoss