开发者

Call or Instantiate? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editi开发者_运维技巧ng this post.

Closed 8 years ago.

Improve this question

I building a website in php where I'll have to make User, Case & Task classes, each of which going to have couple of methods. In my index.php I'll need to do some CRUD operation that I've wrote in my classes. So which is better to call a method and send parameters to like Case::update(2) or its better to instantiate the class first then call a method like

$case = new Case();
$case->update(2); 


Well, as KingCrunch already mentioned in the comments, it totally depends on your whole architecture. Furthermore, it also depends on your preferences. If you read through the following links you may have a better overview and can choose for yourself:

  • Singleton Pattern
  • PHP Patterns
  • Static versus non Static in PHP
  • The Singleton Design Pattern for PHP
  • Static call versus Singleton call in PHP
  • Why Singletons have no use in PHP
  • Difference between static class and singleton pattern
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜