Design patterns for User and Message System...
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: Design patterns for User and Message System...

  1. #1
    Senior Member
    Join Date
    Sep 2011
    Posts
    258

    Design patterns for User and Message System...

    I was wondering though, what are your preferred design pattern for a User and Message System for your application? This is the structure I am considering, but I am not quite sure at this point:

    1. User System:
    • abstract class User
      • class Member extends User
        • class AdminUser extends Member
        • class RegularUser extends Member
        • class BannedUser extends Member
      • class Guest extends User


    Not sure what design pattern this is, its somewhat similar to abstract factory but has lots of differences Id say?

    2. Message System:
    • interface Message
      • class SystemMessage implements Message
      • class PrivateMessage implements Message
      • class VisitorMessage implements Message
      • class Shoutboxmessage implements Message
      • class EmailMessage implements Message


    Seems like a simple strategy design pattern to me?


    So what would you do if you were the designer of a User and a Message System? What design patterns would you use? Id really like to collect ideas, suggestions and criticisms before getting started, thanks.
    Last edited by Lord Yggdrasill; 04-09-2012 at 06:40 AM.

  2. #2
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,886
    I'm thinking maybe you could use the Decorator pattern for User to apply the other sub-types, layering them as needed.
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  3. #3
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Umm sounds like it will work too, I am not quite familiar with how decorator pattern works so would you mind giving me an example of how the user system may incorporate such a pattern? Theres no need to write a complete class with methods, just give me a general idea or a layout of interfaces/classes that would be nice. Thank you so much for this advice.

  4. #4
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,886
    I'll leave it to you to search the web for Decorator Pattern tutorials, but I could possibly see an abstract User class which is extended by a Member class and a UserDecorator class. That UserDecorator class would then be extended by an AdminUserDecorator class and a BannedUserDecorator class. Then if, for example, you need a banned user object, it would be instantiated as something like:
    PHP Code:
    $user = new BannedUserDecorator(new Member()); 
    If there could be such a thing as a banned admin user, it might be:
    PHP Code:
    $user = new BannedUserDecorator(new AdminUserDecorator(new Member())); 
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  5. #5
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    I see, thanks for the example. And yeah, from the textbook I learned PHP it did appear that the decorator class would accept an argument of another object it was supposed to 'decorate'. You even proposed the idea of an adminuser being banned, this is so thoughtful of you.

  6. #6
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,767
    I don't know if its something that will benefit you or not, but if you can use php 5.4 then traits are the way to go for horizontal development. I'm currently working on a project using 5.4 and traits and it has simplified my inheritance and improved my code usability greatly.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  7. #7
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Well I've heard of PHP 5.4 and I personally like the new features such as trait and short-array syntax. The problem is that the software I am developing has lots of users and even developers using older version of PHP. Some were even using PHP 5.2.17, and for this reason we have yet to adopt namespace in our codes. Though about half a year from now we will force users to switch to webhosts that provide at least PHP 5.3.x.

    But yeah, it wont hurt to get started. Trait will be huge in future PHP programming, its time to get ready for that.

  8. #8
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,767
    Ah yeah this project I'm working on is an intranet solution, so I / the customer have complete control of the server, including versions of software, settings, etc. (to be specific I have physical access to the server, with full administrative privileges). However if this wasn't the case I wouldn't be using traits either, as even my own host doesn't support 5.4 yet. It does make things easier tho!
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  9. #9
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Well yeah, the customers/users of your software make a difference. I find it quite annoying how many freehosts and sharedhosts are still using PHP 5.2.17, they are just stubborn or lazy to upgrade. Or you can say they are cowards because they fear too much of script incompatibility after upgrading? Anyway eventually hosts using newer version of PHP will emerge with a cutting edge over the others who refuse to make the move, it is just about time when majority of webhosts switch to PHP 5.3 and even 5.4.

  10. #10
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,399
    Quote Originally Posted by Lord Yggdrasill View Post
    they are just stubborn or lazy to upgrade. Or you can say they are cowards because they fear too much of script incompatibility after upgrading?
    Or you can say they're trying to be somewhat intelligent by fearing script incompatibility after upgrading. After all, shared web hosts don't thrive just because they enjoy upgrading software on their servers - it's their customers that foot the bill every month.

    Upgrade too fast and break the websites of several of your customers and you might find yourself preaching to an empty room about how the latest-n-greatest has more features, is more secure, blah blah (meanwhile your paying customers have already ditched you - despite your good intentions - and taken their money elsewhere, leaving you with all of those upgrade costs and less customers to help pay for it).

    Note I'm not an owner of any hosting company, nor am I trying to defend the ones that lag too far behind (PHP4, anyone?).

  11. #11
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,767
    Quote Originally Posted by bradgrafelman View Post
    Note I'm not an owner of any hosting company, nor am I trying to defend the ones that lag too far behind (PHP4, anyone?).
    To go along with this: I was approached not to long ago about updating a site for someone. I inspected their server and decided to decline the job unless they were willing to change hosts (or have their hosts put them on a different shared solution with new software). Why would I decline a paying job? Well the host was running 4.2.# and TBH I didn't know if I knew how to develop a site that would work in 4.2 heh.

    And yes breaking a customers script to upgrade is bad, that's why often time hosts providing shared solutions often dedicate new machines to new software, and continue to keep older customers on their old software unless requested otherwise!! I was able to get my employers on 5.3.9 instead of 5.1.4 just but submitting a ticket. This makes perfect sense tho, often times people don't care to know how the application works, so long as it continues to work.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  12. #12
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    I do understand the risk, but it is about time for the change. PHP 5.3.0 was released like almost three years ago, and to me about 2 years is long enough to make a move. If you are still using PHP below 5.3.0, you are so outdated. As far as I know, CPanel is compatible with PHP 5.3.x so there should not be excuses. Cant even imagine those still running PHP4, they aint getting new customers lmao.

    Yeah updating your softwares and servers way too frequently does hurt too, I am not saying the webhosts should upgrade to PHP 5.4.0 already as it just came out a few months ago. But PHP 5.3.0? It is already not that new tbh...

  13. #13
    Senior Member
    Join Date
    Mar 2009
    Posts
    802
    Quote Originally Posted by Lord Yggdrasill View Post
    Some were even using PHP 5.2.17, and for this reason we have yet to adopt namespace in our codes.
    My web server at home is still sitting at 5.2.9 I just haven't gotten around to upgrading it. Feels bad man.
    Declare variables, not war.

  14. #14
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Quote Originally Posted by Bonesnap View Post
    My web server at home is still sitting at 5.2.9 I just haven't gotten around to upgrading it. Feels bad man.
    Well I wont say so, it is your own web server at home so you are the only customer, you have full rights and reasons to decide what you want. If you just happen to enjoy PHP 5.2.x or earlier versions, I dont see it a problem. The issue with webhosts is that they need to compensate for requests of advanced customers wanting to switch to PHP 5.3.x, or even 5.4.0.

    Anyway we've strayed a bit from the topic, havent we? XD

  15. #15
    Senior Member
    Join Date
    Mar 2009
    Posts
    802
    Quote Originally Posted by Lord Yggdrasill View Post
    If you just happen to enjoy PHP 5.2.x or earlier versions, I dont see it a problem.
    Nah, I'm just lazy.
    Declare variables, not war.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •