RuleBritannia Posted January 14, 2014 Share Posted January 14, 2014 Hello So I must return a value from somewhere, lets say image total uploaded count from a user account check. The value is returned, used within a loop etc. I also want to update my database with that figure, and a timestamp when it was checked. I know I can put this inside one function, so that after the value check, I can update a table and so on, But this breaks the single responsibility principle, as my function will be doing multiple things. Im curios how you would do this sticking to SOLID principles whilst not making a complete mockery at the same time. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 14, 2014 Share Posted January 14, 2014 Use two functions? But, really, I think this can be achieved in a better way without needing to store the data from the query. You state you want to save the number of images associated with a user and the timestamp of when it was checked. But, if you are storing the uploaded images as individual records in a separate table with timestamps of when they were uploaded, then you can run a query at any time to know what the counts were at any point in time in the past or currently. So, running these queries to get the results and then store that data seems to be counterproductive. Quote Link to comment Share on other sites More sharing options...
RuleBritannia Posted January 14, 2014 Author Share Posted January 14, 2014 Use two functions? But, really, I think this can be achieved in a better way without needing to store the data from the query. You state you want to save the number of images associated with a user and the timestamp of when it was checked. But, if you are storing the uploaded images as individual records in a separate table with timestamps of when they were uploaded, then you can run a query at any time to know what the counts were at any point in time in the past or currently. So, running these queries to get the results and then store that data seems to be counterproductive. The images are not on my server, Lets say for exmaple imageshack.us, I login, check total images, logout. Quote Link to comment Share on other sites More sharing options...
RuleBritannia Posted January 14, 2014 Author Share Posted January 14, 2014 Wondering if this approach is considered good. -> If I was to write a db wrapper, along with a fetch wrapper, And query it like, $objdb->objfetch->imagecount();, Im guessing this would work, Also seperating db actions from string actions etc. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 14, 2014 Share Posted January 14, 2014 The images are not on my server, Lets say for exmaple imageshack.us, I login, check total images, logout. OK, gotcha. I'd probably build a function that gets the list of images. Then call a 2nd function to update the requisite data. But, if you are getting the information from a 3rd party site you probably need some processes to connect to that site and some other things. So, maybe creating a class with all the relevant methods would be a better plan. Quote Link to comment Share on other sites More sharing options...
RuleBritannia Posted January 14, 2014 Author Share Posted January 14, 2014 OK, gotcha. I'd probably build a function that gets the list of images. Then call a 2nd function to update the requisite data. But, if you are getting the information from a 3rd party site you probably need some processes to connect to that site and some other things. So, maybe creating a class with all the relevant methods would be a better plan. Yes I do have a class specifically for fetching the data from the imagehost, But according to SOLID principles, I should be making a second class for database actions, But within the code this seems illogical when it could be handled within 1 class. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 16, 2014 Share Posted January 16, 2014 Right, . . . but at some point following such principles, rules, whatever can actually become counter-productive. If you are working on a large product with many different developers involved then following strict processes is important to prevent problems and make everyone more efficient. But, if you are working on a small, personal project you can dispense with getting too granular. If you have a process that does three things, those three things will always be done the same way, they are relatively 'small', and those three things will never be done independently - it can be easier to build them together. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 16, 2014 Share Posted January 16, 2014 Right, . . . but at some point following such principles, rules, whatever can actually become counter-productive. If you are working on a large product with many different developers involved then following strict processes is important to prevent problems and make everyone more efficient. But, if you are working on a small, personal project you can dispense with getting too granular. If you have a process that does three things, those three things will always be done the same way, they are relatively 'small', and those three things will never be done independently - it can be easier to build them together. That's my two cents. Quote Link to comment 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.