Jump to content

Factory class structure


MrAdam

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...