Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have some classes that are composed with ORM generated Models.

example1: For example the Report.php (Model) is using a Document.php Model generated with ORM. Based on the document object a report is created.

I would like to know some name suggestions for the Report.php folder path. It clearly belongs to the /Model folder but in what subfolder?

example2: The CustomTagFilter.php will remove some html tags from a html string.

I wish to find a clear path name for this kind of Models. Any suggestions ?

/Models/[SUGGESTION]
share|improve this question
    
So, to clarify, the Document class represents documents held in the in the database via ORM? The Report class represents temporary data used to generate a report but is not persisted? Also, why do you think CustomTagFilter is a model class? –  redbirdo May 10 '13 at 9:31
add comment

3 Answers

up vote 1 down vote accepted

There are no rules on how you should organise your model code. Mostly not because it all depends on your application. At best, we can give you some food for thought.

In a small application (up to a few dozen model classes), I might not even bother with organising them in separate folders.

If a more structured organisation of the model classes is deemed beneficial, I would first group the classes according to functionality, so all the ORM related classes together, the classes dealing with functionality A together, etc. If still more organisation is needed, add another layer using whatever division seems right at that point.
For the posted examples, the division would probably come to

  • Models/
    • ORM/
      • Document.php
    • Filters/
      • CustomTagFilter.php
    • Report.php

The only thing to avoid is to use catch-all categories. If you can't think of a good category name, don't put it in a sub-category at all (like I did with Report.php).

share|improve this answer
add comment

ORMs are working with Entites, which are basically the instances of the model classes (in your case Document.php), so calling your folder Entities would be logical.

To get a proper definition of Entity, dive into the documentation of the ORM you are using. (Here is an example from the documentation of Doctrine.)

share|improve this answer
    
/entities/report.php sound a bit strange when you think what an entity should be. –  danip May 7 '13 at 8:50
    
Ok, so what I would do is put the ORM generated entities in /Entities/ or /Models/Entities/ folder, and the models created by you (if I understand correctly report.php is one like this) can be put in /Models/ or maybe /ViewModels/ folder. –  Andras Toth May 7 '13 at 11:57
    
But isn't the term entities coming from DDD? In pure MVC is the entities folder a valid name conventation? –  danip May 7 '13 at 12:02
    
I'm not quite sure about this, maybe someone more enlightened can clarify this. However I always met the phrase Entity in context of ORMs. And I think using an ORM adds a new layer to your app anyway, which helps the separation of concerns, and I guess this is your ultimate goal after all. –  Andras Toth May 7 '13 at 13:26
add comment

I'd go with Transformers if I was in a whimsical mood:

/Models/Transformers/Reports.php
/Models/Transformers/CustomTagFilter.php

or Translators if I was feeling more business-like:

/Models/Translators/Reports.php
/Models/Translators/CustomTagFilter.php
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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