Classes. What's the point?

后端 未结 12 1904
夕颜
夕颜 2020-12-03 03:09

I\'m fairly new to OOP in PHP, I\'ve made a couple of basic scripts but nothing impressive. All I\'ve really taken from it is that it would probably be easier just make a co

12条回答
  •  天命终不由人
    2020-12-03 03:58

    If you're just writing procedural-style functions then slapping them together into a class you're not going to get many of the benefits of OOP. I think that the Open Closed Principle and the Dependency Inversion Principle describe some of the biggest benefits of OOP, which you wont get unless you intentionally design them into your code.

    OOP isn't perfectly suited to everything, though. I think procedural programming is well suited to web development. It involves converting a (fairly) simple request into a bunch of HTML, which is a highly procedural task. If it's simpler to include a few functions, there's no point trying to shove an OOP shaped block into a procedurally shaped hole. However, I imagine that OOP would be the better option if the website was very complex.

提交回复
热议问题