Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting a Play! 2 application into modules

I am learning Play! 2 for Scala, coming from a Django background. In Django I was used to being able to modularize a project by dividing it in various applications, each having its own models, views, controllers and assets. Does Play! allow a similar subdivision of a project or it is mandatory that everything goes under the app directory?

EDIT I already got the answer, but I will make some examples of the use of Django apps:

  • The admin is a separate app
  • An app can be used to define abstract models for internationalization. Actual models that need to be internationalized can inherit from them
  • I created an app that defines a Facebook user model, managing the Facebook API, and exposes is to other applications that need it
  • There exists a Django app to generate a sitemap programmatically
  • Another Django app allows to create a robots.txt from rules stored in the database, so that one can edit robot rules from the admin interface

and so on

like image 834
Andrea Avatar asked Aug 02 '12 07:08

Andrea


People also ask

Why split code into modules?

Modules can be stored in separate files, and function and constant names will be unique to each file, but not the whole program. And modules can be easily re-used in different projects, without copying and pasting.

What is a multi module app?

A project with multiple Gradle modules is known as a multi-module project. In a multi-module project that ships as a single APK with no feature modules, it's common to have an app module that can depend on most modules of your project and a base or core module that the rest of the modules usually depend on.

How do you split an application into modules?

One rule of thumb is that you can often split the application into modules based on package boundaries. Thus, if you have the following packages: You might refactor this into a GUI module, a data module and a logic module. As you continue development, you might find that these could be split even further.

How do I split a tomwheeler application into modules?

One rule of thumb is that you can often split the application into modules based on package boundaries. Thus, if you have the following packages: com.tomwheeler.app.gui. com.tomwheeler.app.data. com.tomwheeler.app.logic. You might refactor this into a GUI module, a data module and a logic module.

How to use a component in multiple modules?

Also, a component (or ... you got it) can only be declared in one module. If you want to use your component in multiple modules, you need to bundle that component into a separate module and import that in the module. Speaking of importing... Your module can import as many sub-modules as you like. Don't have defined any custom modules yet?

Do you prefer big or small modules in an app?

In general, I definitely prefer to have lots of little modules than a few big ones. If you're designing a new app from scratch, it's easy to achieve "smallness" in your modules and you'll have a better design (less coupling) because of it.


2 Answers

Maybe sub-projects are what you need. It would help if you would describe a little why you want to modularize and what a module should consist of from your point of view.

like image 153
rretzbach Avatar answered Sep 21 '22 09:09

rretzbach


Just a little update on the thread. From 2.1 Play supports routing mapping of sub-modules:

https://github.com/playframework/Play20/blob/master/documentation/manual/Highlights.md#allow-more-modularization-for-your-projects

like image 21
agabor Avatar answered Sep 17 '22 09:09

agabor