Making a OOP forum [closed]
I've learned the basics of OOP and though I should attempt to make something simple, (just to learn and because I'm bored). The problem is I'm having trouble deciding what classes I'm going to need. Database abstraction and (user input) validation pretty much sort themselves out. It'll be in PHP, but I think all forums designed in OOP share a common set of classes.
The forum will be very simple, register, login, view, post and reply. I was thinking something along the lines of the list below:
- Registration class
- User class: class to manage users
- User_Post class: class to manage user posts
- Posts class: manage posts
- Validation class (PHP filters?)
To me Hierarchical threading seems incredibly complex to program for a noob like me. A really simple forum I like is the BBCs 606 forum.
Maybe openID for validation?
Thats all I got so far.
If you "think all forums designed in OOP share a common set of classes", why not do some surgery on existing software? (There is a load of open source forum-software out there.)
That way you'll learn about the common set of classes, how they work, interact and the overall process of building a larger piece of software.
My guess is that equipped with that knowledge you'll be far better of building your own forum than with any answer (or rather: opinion) about what classes you should use or need.
For the login I would´nt recommend openID I thik you would be more "part of the process" if you srt with something like this.
It is simple enough and will be more in line with a PHP forum in my opinion.
I would also take a look some reference is some good "simple" php forums out there like PunBB
Good luck!
If you abstract properly, you will realize the benefits of OO and Active Record. Then you will be able to walk upon the rice paper without making a sound.
Design tables, then build one class per table. Be strict with noun(s) and verb(s).
ex:
users
id
username
password
forums
id
name
posts
id
user_id
body
forum_posts
id
forum_id
post_id
There are 3 classes here:
- User
- Post
- Forum
By using static methods in the appropriate class, you can build this intelligently:
$user->forum_posts('id DESC');
# function forum_posts($order_by) { return Forum::get_for_user($this->id, $order_by); }
$user->forum_post($forum_id, array('body' => 'Foo'));
# function forum_post($forum_id, $array) { return Forum::post_to($forum_id, $this->id, $array); }
continue like this. think about very small pieces and every thing will come together. Give every class a list of fields, __call, get(), set(), and factory methods to get related classes
精彩评论