Question

Im designing a MVC framework but I dont know where should I put my utility classes. I read somewhere where it said utility classes are Model Classes. Is this line of thinking correct or are they some separate type of class?

Was it helpful?

Solution

It depends on what these Utility classes are doing. The main idea of MVC is to separate the presentation layer (V and C) from the remaining application (M). If your Utility classes handle things related to the presentational layer, place them in an appropriate package, for instance ViewHelpers or InputHandlers. If the Utility functions relate to anything else, see to which layer in your model they best fit into, for instance DataAccess Utilities go into the DAO package while a a MailHelper might go into the the Services package, and so on.

OTHER TIPS

Model class can contain your data access code, application logic. so it is okay to place in Model.

The best approach is to create a folder Utility in Model folder and place utility class there.

If it isn't a representation of stored data, then it's probably not a Model class. Even then, if it still represents stored data of some sort, but behaves radically different from the rest of your Models, it may not belong with the rest of the Models, anyway.

Utility functions can be part of the whichever class they are utilities to, either Model, View or Controller. If they're a bit more generic, then they kind of live "outside" the MVC design.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top