where to put interfaces in mvc

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
pfeatherstone
Forum Newbie
Posts: 1
Joined: Wed Apr 20, 2011 2:20 pm

where to put interfaces in mvc

Post by pfeatherstone »

Hi all,

Sorry if this is in the wrong section but here goes!

I have developed my own mini framework to use for testing and I have started to use interfaces. At the moment I have an interface for my abstraction object in my controllers where I then implement as part of my class. I'm not sure where interfaces are actually supposed to live - in a separate file / section?

Not sure how the 'commercial' frameworks such as zend et al integrate interfaces into the MVC architecture (as I am new to these too!)?

Any pointers / insight would be much appreciated.

Thanks in advance.

Regards,
Paul
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: where to put interfaces in mvc

Post by Christopher »

Interfaces are usually put in their own files and located with the files that implement that interface.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: where to put interfaces in mvc

Post by josh »

Interfaces are used within all layers. (model, view, and controllers). You can put them anywhere as long as they are included by the compiler (explicitly or with autoloading), there are different convensions. Some people prefix it with an I for interface, like "IOutlet", others add "_interface", like "Outlet_Interface". Others name the same as classes, like "Outlet" (the fact it is an interface isn't apparent from it's file/member name, this is my preference). You can literally just cram them all in the same file as the classes that implement them, it just wouldn't be considered clean.
Post Reply