Jump to content
MrAdam

Factory class structure

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

It sounds like part of the model, but I haven't used enough MVC frameworks to give a good answer.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×