Extending Model

Daniel Hood

Well-known member
I'm about make an addon that makes use of a new function I'm going to add to the User Model. I don't imagine anyone else using it. I know the common practice is to extend using the proxy system, but I don't think it's necessary to load my class every time the user model is called upon, so I'm considering using

PHP:
 class My_Model_User extends XenForo_Model_User

and then calling
PHP:
 $model = XenForo_Model::create('My_Model_User');
instead of calling the XenForo Model. I just want know if people are going to view this as bad practice? I'm basically wanting to not sacrifice performance where it's not really needed (which is anywhere besides my addon).
 
I'd view this as pretty bad practice.

Just extend the model with the class proxy system. That's what the code events are for, use them always where it is possible to do so.

To reduce the impact of loading your class, when you create the event listener, use XenForo_Model_User as the event hint and that's the best you can do.

Bear in mind until 1.2 we didn't have event hints at all, so even if you do it the proper way, overall the performance is better than it was in 1.1.x anyway.
 
Never extend a XenForo class directly. You should always use the Class Proxy system. You may not think its necessary but the extension is not much of a memory/time hit and it guarantees proper functioning of other add-ons that may in turn end up working with yours.
 
I'd view this as pretty bad practice.

Just extend the model with the class proxy system. That's what the code events are for, use them always where it is possible to do so.

To reduce the impact of loading your class, when you create the event listener, use XenForo_Model_User as the event hint and that's the best you can do.

Bear in mind until 1.2 we didn't have event hints at all, so even if you do it the proper way, overall the performance is better than it was in 1.1.x anyway.

Never extend a XenForo class directly. You should always use the Class Proxy system. You may not think its necessary but the extension is not much of a memory/time hit and it guarantees proper functioning of other add-ons that may in turn end up working with yours.

Fair enough, I was on the fence as I knew it was wrong to ignore the code event system but I figured what's the point of my file being included for no reason, no big deal either way. My function (or two) won't cause too much overhead regardless.

Thanks for your feedback
 
Back
Top Bottom