|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
need help with OO design for my site
Hello:
I am trying to develop my own personal website but I am trying to do it by following OO concepts. Now although technically it shouldnt matter what I am using since the OO design should work with anything this is what I got: - Apache webserver, with myslq database and php on it. The part that I am caught up in right now is in the the design of the database object. I am not sure that I have designed it properly and that I am doing alot of things incorrectly. I have split the database object into 2 classes, the first is the actual database and its properties looks like this: 1. Name: Database() Description: The constructor. It Initializes the $server, $username, $password and $database class members 2. Name: openConnection() Description: Opens the connection to the database server and selects the database (uses the property selectDatabase) 3. Name: selectDatabase() Description: chooses a database to work with 4. Name: queryDatabase() Description: queries the database and initializes the $queryResults class member to the results of the query 5. Name: returnResults() Description: Returns the $queryResults member 6. Name: insertRecord(), deleteRecord(), & modifyRecord Description: These properties pretty much run an SQL statement and return a message saying how many rows were affected (if the query was successful). 7. Name: displayResults() Description: Displays the contents of the $queryResults class member by creating a new ResultsPAge (read below) object and calling its display() property. OK that is pretty much it for the properties, the class members (or class variables) $servername, $username, $password, $dbName and $queryResults. Pretty much all of these (except the $queryResults) are initialized set by the constructor. The other object or class that I have that goes hand in hand with the database object is the ResultsPage object and this is what I am having problems with. In essence I created the ResultsPage object in order to have a flexible way of displaying whatever results get returned from an SQL query. The main purpose of the ResultsPage is that if the number of results that are returned is very high it displays the webpage with the ability to page through the results. When I thought about it, the scope of what this does is really what a WebPage object would except that it is pretty specialized to displaying records only so it didnt quite seem to fit in the scope of a Database object (which is only supposed to connect to a database, and query it) so that is why I made it its own object. The properties in the ResultsPage object look like this: 1. Name: ResultsPage($recordSet,$pageSize) Description: The constructor. Initializes the $recordSet, $pageSize, $numberOfPages, $numberOfRecords, and $currentPage class members 2. Name: setCurrentPage($page) Description: Sets the class member $currentPage 3. Name: setStyles($headerStyle,$recordStyle,$recordAlternateStyle,$buttonStyle,$frmElementStyle) Description: This property sets all of the styles that will be sed to display the page. 4. Name: display() Description: this is the function that creates ALL the HTML to lop through the recordset to create the page. If it happens that record paging functionality needs to be added this function also displays a record navigating form at the bottom of the page so that a user can jump from page to page. The class members or variables for the ResultsPage class are: $headerStyle, $recordStyle, $recordAlternateStyle, $buttonStyle, $frmElementStyle, $recordSet, $currentPage So by now you are all probably shaking your head and saying "he should have never picked up an OOP book." As you can tell I need help. From what I can see my main problem is the display() function of the ResultsPage object, if you were to see the implementation code for it you would see that it is about 50 lines long and it has so much embeded HTML and echo statements I dont know if I should be separating all of this or what. The main reason why I have done it like this is because there is a specific way in which I want the results pages to look, if there are more than so many records than there is a specific way that I want it to be able to page. and dont get me all wrong, I actually managed to get it to work. But when I am creating the database object and the pageresults object on the page that the records will be displayed from it seems like I have to end up doing more work than I should. I am going to post the implementation code for the resultspage object below if you want me to post the code for the Database object I can do so as well. ResultsPage: PHP Code:
|
|
#2
|
|||
|
|||
|
and I also decided to post the code for the database object:
PHP Code:
and a page where I would use the database object would look like: PHP Code:
|
|
#3
|
|||
|
|||
|
Just a couple more things to mention here are that I know that is alot of code and I dont expect anyone to go through it and tell me what lines to change. What I want is an idea of how I could change the design to resemble more of an OO design and make it more efficient, the code is pretty much documentation to show you what I have done. There are a few more properties in the code that I didnt mention only because they werent that relevant. Either way any help at all would be appreciated.
There is another object in those pages if you have noticed it is a Form object which is used as the navigation form for the records. Thanx in advance for any help you can give me. |
![]() |
| Viewing: Dev Shed Forums > Other > Project Help Wanted > need help with OO design for my site |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|