After explaining what’s a modular application, I’ll now explain with more details the concept of modules.
We said that a module add features to the application. But before writing any code, we’ve to define exactly what are the modules, what they can do if there is several types of modules, …
This is what we’ll see in this post.
The first question to ask is “What can a module do ?”. Namely, defining all the things a module can add to the application and how they can add these things. Moreover, a module can also modify the application.
What the modules can do depends on the type of the modular application :
- For the first type (simple application with extension capability), the module adds specific features depending on the application. By example, in the case of an application that allows to watch television from internet, the modules can add a new channel or the support of a new video format. It can also adds a complete feature like statistics about channels.
- For the second type (empty application and modules that make the application features), the modules don’t add features to the application, they do the application. In this case, the modules are often bigger than in the first case, because, modules are applications. There is often no links between modules, one can create a calculator and the other a video editor.
In the two cases, we’ve to define several extension points. By example, here are the extension points I created for JTheque :
- Add tabs in the main view
- Add components in the state bar
- Add features to the menu
- Add configuration options
With there extension points, the modules can do a lot of things. If we want to make a calculator, we can add a tab in the main view or add a feature in the menu that displays a calculator in a dialog. Of course, this extension points depends of the developer and the application, but this is really important to define well a list of this points.
More than providing extension points, the core of the application provide also a set of services to the modules. These services can be simple utility classes or by example a persistence manager or a file manager.
One more time, you’ve to decided which services the core will provide to the modules. This services are not essential, but that enables to simplify a lot the modules. And that improve the code standard of the modules. With that model, the modules will always use the same type of services, this is easier to manage.
By example, here are some of services, JTheque Core offers to the modules :
- Error manager : To display some errors.
- View manager : To create easily new views, display messages, ask something to the user.
- Resource manager : Provide an image cache and utility methods to load image, create thumbnail, …
- Persistence manager : Give the ability to modules to persist objects
- State manager : Store states for modules
We can also think if we want only one type of modules or several. By example, you can imagine primary modules and normal modules. Only a primary module can be launched at the same time.
The last point I see, is the point of the dependencies between modules. We can allows that a module depends on an other modules. This add a difficulty level for the implementation, because we must verify that the dependencies are solved before launch a module. And what about circular dependencies ? This is the choice of developer, but if you don’t allow dependencies between modules, it can e difficult to create good applications.
So I’ve finished to talk about modules. Don’t hesitate to comment if you doesn’t agree with something or if you have questions. In the next I’ll implement the first modules and in the last, I will create a simple loader for modules.