LocoCoco
Programmer
- Sep 20, 2008
- 2
I'm on my way familiarizing myself with object oriented design in PHP (MySQL). I wanted to realize a very simple and stupid example to see how it's supposed to work, but it turned out being more complex than I thought.
This is what I want to realize:
Basically I have Students that can do Tasks from various categories.
When a Student calls the page (index.php) he should be asked to enter his/her name.
PHP opens a MySQL connection and gets the Students ID from the Database.
Then all the available Categories are retrieved from the Database.
Retrieve all Tasks to the Categories.
Check if this Student with this particular ID has done this task, output yes if so, otherwise no.
I came up with the following UML class diagram (I hope I didn't misinterpreted the conventions)
The class Workshop is the central class that holds all the other classes (aggregation). The constructor from Workshop is called when the site gets loaded. Workshop instantiates and initializes an object from the class Student. An object of CategoryArray is initiated and initialized with all the categories in the database, every Category Object in the Array gets its tasks from the database (this works by passing the Category string to each category object on creation, so that it knows what category it has to take care of).
The Workshop iterates through the CategoryArray object as well as the CategoryArray iterates through the Array of Tasks (would it make sense to add a TaskArray class?). Every task gets checked whether it has been solved by this student or not.
Is this how an object oriented design would look like or is it totally useless? I'd like to discuss with the users of this forum to get valuable input. I appreciate suggestions on how to improve my solution, I'm not asking anyone to do it for me since I'd like to learn how to really think object oriented - but I need to know if I'm on track!
I hope someone has time to think about it for a moment and shares his/her opinion.
Thank you in advance
coco
I've read the Posting Policy, and my contribution/question to this forum has absolutely nothing to do with homework!
This is what I want to realize:
Basically I have Students that can do Tasks from various categories.
When a Student calls the page (index.php) he should be asked to enter his/her name.
PHP opens a MySQL connection and gets the Students ID from the Database.
Then all the available Categories are retrieved from the Database.
Retrieve all Tasks to the Categories.
Check if this Student with this particular ID has done this task, output yes if so, otherwise no.
I came up with the following UML class diagram (I hope I didn't misinterpreted the conventions)
The class Workshop is the central class that holds all the other classes (aggregation). The constructor from Workshop is called when the site gets loaded. Workshop instantiates and initializes an object from the class Student. An object of CategoryArray is initiated and initialized with all the categories in the database, every Category Object in the Array gets its tasks from the database (this works by passing the Category string to each category object on creation, so that it knows what category it has to take care of).
The Workshop iterates through the CategoryArray object as well as the CategoryArray iterates through the Array of Tasks (would it make sense to add a TaskArray class?). Every task gets checked whether it has been solved by this student or not.
Is this how an object oriented design would look like or is it totally useless? I'd like to discuss with the users of this forum to get valuable input. I appreciate suggestions on how to improve my solution, I'm not asking anyone to do it for me since I'd like to learn how to really think object oriented - but I need to know if I'm on track!
I hope someone has time to think about it for a moment and shares his/her opinion.
Thank you in advance
coco
I've read the Posting Policy, and my contribution/question to this forum has absolutely nothing to do with homework!