MrAdam Posted July 4, 2011 Share Posted July 4, 2011 Hey up everyone,I'm designing my own MVC-based framework. I'm not trying to re-invent the wheel or anything, I just want a simple, custom platform I can build my projects on. I'm implementing some objects (for example User) and creating a factory class (for example UserFactory) that handles constructing the object in various ways. There's an abstract base Factory class that each factory would extend to provide some generic functionality.I'm a little unsure how to structure the factory classes though. Would you say that it's acceptable to have both the User class and UserFactory class within the same file? That way I only need to include User and have UserFactory available. Or do you think it's more appropriate to have them in individual files, and have UserFactory include User?ThanksAdam Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2011 Share Posted July 5, 2011 For the sake of maintenance it's probably easier to have them in separate files. You can either have one file include the other file that it requires, or use autoloading when you try to instantiate a class that doesn't exist. Link to comment Share on other sites More sharing options...
MrAdam Posted July 5, 2011 Author Share Posted July 5, 2011 Thanks for your reply.I did think of autoloading the class, but due to the structure of the files I can't see any easy way to do that other than to have it check two directories. Would you say that's acceptable for autoloading? I want it to be as quick and snappy as possible, while keeping a very organised structure. I have the traditional "controller/", "model/" and "view/" directories. Only the "model/" is necessary for autoloading, as the controllers and views are resolved in a different manor.The second directory mentioned is a library of classes that contains the core components of the framework; the DB classes, the base Model, Controller & View, etc. That's already autoloaded in a Zend-like way. Would it be fine performance-wise to include the "model/" directory? Or if not, does another suggestion come to mind?Thanks again for your help..Adam Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2011 Share Posted July 5, 2011 Within your framework you probably shouldn't use autoloading, just for the sake of efficiency. You can use autoloading in the applications that use your framework to autoload the entire framework, but when the framework is loading its various pieces it's probably best to hardcode those paths. Link to comment Share on other sites More sharing options...
MrAdam Posted July 5, 2011 Author Share Posted July 5, 2011 That makes sense, thanks.One other question.. Where would you think is the right place in a typical MVC-based framework to store such objects? For example the project I have in mind at the moment, certain parts of it (employees, clients, etc.) I want to create an Employee, or Client, etc. object to represent them. Obviously straight-forward OO, but where would that make sense in an MVC-based framework?Thanks for your help.Adam Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2011 Share Posted July 5, 2011 It sounds like part of the model, but I haven't used enough MVC frameworks to give a good answer. Link to comment Share on other sites More sharing options...
MrAdam Posted July 5, 2011 Author Share Posted July 5, 2011 No problem, thanks anyway. I've looked at several different frameworks and they all have their own approach to models, but none seem to be what I'm after. I'll keep digging! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.