Jump to content

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/266898-extending-3-specific-classes/
Share on other sites

#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.

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.