Play! framework uses a of statics

后端 未结 14 1893
太阳男子
太阳男子 2020-12-07 15:29

Waaah, the Play! framework has so many static methods. Where I go to school, we were told never ever to use any statics, yet Play! uses it like there\'s no tomorrow

14条回答
  •  眼角桃花
    2020-12-07 16:18

    Statics method in play are mainly used in controllers action methods. These methods are meant to just fetch the necesary data from the model and expose it to views.

    They correspond somehow to each possible http request, and, just like those http request are completely stateless.

    On structural programming you have procedures on the one hand, and variables on the other, but on OOP paradigm you treat procedures and variables as a whole.

    That is, you have and object with instance methods (procedures) and instance variables.

    But controller actions are stateless, that is they get all there variables from the request (maybe also from the cache, but in that case you need some sort of session id that finally comes from the request). So controller actions are just like stateles procedures, and that's why they don't particularly fit in the OOP paradigm, as models do.

提交回复
热议问题