开发者

Is it worthwhile to implement observer pattern in PHP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
开发者_JS百科

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 5 years ago.

Improve this question

I have been meaning to make use of design pattern in PHP, such as the observer pattern, but that I have to recreate the observers' relationship each time the page is loaded pains me. As references are saved as a new concrete objects in session, there is no way to preserve relationships between subscribers and their observers unless you use a GUID or some other properties to form a lookup, and store that property instead.

With the cost of recreating the relationships each time a page is loaded, is it worthwhile to use design patterns such as observers in PHP, compared to having a clean design? Any real-world experience to share?


That's a somewhat odd question to ask for a programming language that - by design - shares nothing and recreates the entire environment on each request anyway.

When talking about cost, you have to take into account that finding and recreating the session data on each request takes up resources too. I don't know how many relations we are talking about in your app, but attaching all required subjects with observers in a bootstrap sounds like a clean and valid approach to me. You could push the responsibility for this into a manager class for increased maintainability.

If in doubt about performance, benchmark.


The recreation of the relationships themselves would probably take the least amount of time, since the objects are passed around as references.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜