fry2010 Posted August 10, 2012 Share Posted August 10, 2012 I know this is a common question in relation to object oriented coding, but the answers I see in other places don't really explain how to deal with my situation (probably a very common one). Basically I have created an abstract class 'model', I then want to extend on this with class 'userModel'. Now here is the issue, I also have a third class 'pagination' that I want to be a available to the 'userModel' class. Is any of these approaches the correct way: 1) I could extend the 'model' class with the 'pagination' class, then extend the 'pagination' class with the 'userModel' class. So 'model' -> 'pagination' -> 'userModel' - However these just seems wrong to extend the pagination class 2) Put the 'pagination' methods inside the 'model' class and just extend the model class. So 'model' -> 'userModel'. - However doesn't this go against the seperation of behavoirs with classes? 3) Don't extend the pagination class, but call it seperatly in my control code. The typical answers I see basically suggest that the structure of the classes are wrong if I find I come accross this issue, yet to me the classes seem to be seperated logically. As in they each lay the plans to well defined behavoirs. So I don't see how they can be re-structured. Please enlighten me on where I am going wrong with my thinking here... Quote Link to comment https://forums.phpfreaks.com/topic/266898-extending-3-specific-classes/ Share on other sites More sharing options...
KevinM1 Posted August 10, 2012 Share Posted August 10, 2012 #3 is your best bet. Pagination is not a Model, and Models are supposed to be 'dumb'. You should be able to query for the right data (in this case, the right set of db rows for a particular page), but the Model itself shouldn't be concerned with how its data is presented. It's primary concern is with data access/persistence. Assuming this is a MVC setup, the controller is the middle man. It should know what page has been requested, and query the Model for that data along with a count of all rows. It should then pass that data to the Pagination, along with ancillary info, like items per page and total number of rows, so it can properly display navigation. EDIT: Actually, your Pagination class should only have the ancillary info. Actual data should just be piped into the view. Again, separation of concerns - pagination only cares about page navigation, not actual data. Should have been clearer on that. Quote Link to comment https://forums.phpfreaks.com/topic/266898-extending-3-specific-classes/#findComment-1368373 Share on other sites More sharing options...
fry2010 Posted August 10, 2012 Author Share Posted August 10, 2012 Ok that clarifies a lot for me. You seem to understand exactly the issue I am getting at here, the fact of getting the pagination to work with the result set from the model, without being integrated. I just wanted to avoid having to request a method twice with effectivly the same sql query. So I believe my design issue is with my control aspect. Cheers Kevin Quote Link to comment https://forums.phpfreaks.com/topic/266898-extending-3-specific-classes/#findComment-1368394 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.