Serious Website Design Discussion

Discussion in 'PHP' started by mailcol, Apr 22, 2007.

  1. #1
    hi, i had exp on PHP coding bout 3-5 yrs. And i had try different approach in designing my system. And something bugging me, when i design my system, like OOP, class, different classes and conflict between them, etc. So i decided to post my question here.

    1. How good OOP Are?
    - For a normal website design, we may have this situation, A MEMBER class is designed and a method "sendPrivateMessage" is given to it.
    - What's cooking behind this kitchen is just adding a record to the member_privmsg table via another mysql class
    - It's FAST and transparent from DB layer, even email layer sometimes
    Problem Here
    - What if we have another ADMIN Class, should we give it another "sendPrivateMessage" method?
    - Problem getting worst coz my system consider different context. Sometimes a member can be admin and vise versa for different context of the system.
    - Can someone give me guidance? May be i am confuse with the meaning of OOP
    - from my point of view Web Dev OOP is a bit different with other offline sw OOP. Coz online Web Dev always, Almost 90% of each action/Biz logic related to DB interaction (i think tht's the reason many DB class comes out)
    - If i keeps on OOP my design, i will have many class like MEMBER, ADMIN, GROUP, etc and all need an establish of DB connection inside. It will consume resources when suffer from high traffic

    2. What i saw from the Net

    - MOST of the class i get from net, is quite distinct,
    ezSQL+ezResult(db interaction and pagination format)
    smarty(template engine which try to seperate Controller&View as much as possible)
    snoopy (simulate browser)
    pdf class
    phpmailer​
    - All classes above did their job well. And i trying to implement/mixed them(mysql class+mailer class) to my Member class(to make my Member class have email and Biz knowledge) then it becomes suck :(
    - So i wonder making DB, Mailer etc layer transparent(hide inside Member class) is a good idea? Coz everytime it just consume my time in tweaking it.
    - Can some senior guide me?

    3. What i found from net package
    - I had research on certain number of php sw from net. phpmyadmin, mambo, other CMS package, they seldom do a Member class, and what they did, they just distribute their system MODULEs, then making each module transparent to each other, by just including a library, then start coding
    - So, normally from their *.php(not class/lib script) script, they expose lots mysql queries, and maybe configuration of mailer. So, it's not CLEAN, but at least it's more easy to start coding compare to what i mention OOP above, rite?

    I am sure they must be some folks facing same problem like me. So i open this discussion here :cool: Or maybe i am getting the wrong path towards of OOP? :p Then someone can bring me back to track
     
    mailcol, Apr 22, 2007 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,893
    Likes Received:
    4,553
    Best Answers:
    123
    Trophy Points:
    665
    #2
    From quickly reading your post I think one of the things you are tripping over is the concept of modularity and reusability.

    There should be no need to create multiple database connections if you have coded right. And yes, you will end up with lots of classes to manage the data right.

    For big projects this will be invaluable. For smaller projects it'll be a headache. Choose the right approach for each job.

    If you apply an MVC approach (see CakePHP as example) you'll find the structure quite easy to understand. It's just a learning curve.
     
    sarahk, Apr 22, 2007 IP
    commandos likes this.
  3. mailcol

    mailcol Peon

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, let me hv a look :)
     
    mailcol, Apr 23, 2007 IP
  4. Weizheng

    Weizheng Peon

    Messages:
    93
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Interesting discussion. I think the 2 most important things are:
    - components that are modular
    - well defined interface to each component

    In your first example, I'll have the DB and Messaging modules. Then I'll have a User class that does messaging via Messaging module that uses the DB module. Member and Admin would extend Member class and inherit the messaging capability. If I want to disable messaging for Admin, I can do it in Admin class.

    As for integrating packages from the net, I'll create an interface module. All calls to external packages would go through this interface. I can easily replace any of these external modules by simply rewiring this interface.

    I dont think the open source coding style is a good example for individual coders. Most people just want a quick fix without bothering about reuse and ease of maintaining the code.
     
    Weizheng, Apr 23, 2007 IP
  5. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #5
    Always,

    -> Use Modular Classes, as such PHP is fast.
    -> Always optimize your code as it tend to slow down server.
    -> Focus on optimizing mySQL queries than php code.
    -> Use smarty if you need caching as caching is needed for high traffic sites.
     
    olddocks, Apr 23, 2007 IP
  6. mailcol

    mailcol Peon

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for your interest on this topic.

    Yeah, i am the one who have this attitude, i rather use pdf generator class, snoopy, ezSql to mix with my proj last time, but this time i hope to sharpen my php skill by learning those design pattern :D

    I adopt smarty coding style, and several of the system i code for my company also using it. I love it much. And honestly, i do use Member, User, Tracking, etc... many classes which finally messup my code :confused: And i also study those OOP, design pattern, and i get even more questions when i found appModel class, iterator class, etc class which totally 100% no idea on them coz they dont hv direct relationship to M(Model)VC. My current php standard is just can link up my class with those Biz Model

    This time, i hope to use php to act as backend, and openlaszlo to become front-end. I think it cost me another few month to learn them :rolleyes:
     
    mailcol, Apr 23, 2007 IP