2011-11-18 11:50 阅读 18


My goal is to write some reusable (OO) code for communicating with an external API, but as I'm not well versed in this kind of stuff in PHP, I'm not sure what is the best way to organize and load my code.

Stuff like limiting the amount of knowledge the client code needs to have about the libraries classes and making sure there are no naming collisions has led me to experiments with namespacing and avoiding having to inlude all the library files have led to experiments with autoloading, but I have so many questions on the subject that in stead of a lengthy process of trial and error, I thought I'd see if I anyone here possessed some wisdom on the subject.

So I guess my main questions are:

  • How to best encapsulate the library code, making it stand on it's own as much as possible.
  • How to best load/call this library code from the client code.

... but feel free to expand on whatever you think should be considered. :)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    douhuan1905 douhuan1905 2011-11-18 12:15

    The best way to go about it is simply to check how others do it Both Zend Framework and Symfony for instance will have a clear separation between these two. May not be a bad idea to borrow some concepts and make them your own.

    I tend to simply put my library code and 'client code' in separate namespaces.

    点赞 评论 复制链接分享
  • dtry54612 dtry54612 2011-11-18 11:58

    What I can say that use OOP in php code to organize your code and reusable.

    You can easily make a standalone class.

    点赞 评论 复制链接分享