On Mon, Sep 2, 2013 at 8:42 PM, Michael Zhang <m...@solumtech.com> wrote:
> Hi guys, > > My name is Michael Zhang, and I am very new to Pyramid. I have a quick > question in designing a large web application backend, and hope the > community can help me out. I really appreciate your help. It helps me to > learn and get my job done. > > My question is simple: what are some good strategies in organizing common > methods or classes for operations that we might constantly use in our > applications? For example, if we have a method to collect all the comments > belonging to a blog post, where we should put this method/class in our > application in a clear and organized fashion? To us, there are potentially > two choices: > > Choice A. We can define our model Blog, and inside Blog, we can define a > method like getAllComments. > > Choice B. We can separately define BlogCRUD class, that has methods to get > all comments. > Choice B sounds too pedantic and Javaesque. There's no reason you *can't* put methods like this in your models. However, you may choose to keep them separate for convenience. I'm actually deciding that right now as I port a Pylons application that has all queries in high-level model methods. I got tired of mixing these kinds of queries with model instance methods (e.g., to format a field or group of fields). Then I realized I could put those high-level methods in the resource tree, and that would separate them from both the model modules and the view modules. That partly depends on whether you want to have a resource tree, whether you want to use traversal, and whether you'll have access control lists. To me it seems to come down to application size: the resource tree is nice in large application, but overkill in small ones. The main separation I make in my applications is between the model and everything else; i.e., the model can't depend on or import other parts of the application, so that it can be used standalone or with another framework/user interface. So I have an 'init_models(engine)' function that sets the engine, and if I needed to pass any INI settings I would pass them as individual arguments to that function. -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-devel+unsubscr...@googlegroups.com. To post to this group, send email to pylons-devel@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-devel. For more options, visit https://groups.google.com/groups/opt_out.