Plugins and Services (Building blocks)
What is a plugin?
You can think of a plugin as defining a type of functionality (e.g. Field, Importer) that (a) has or will have multiple implementations and (b) a single site may want to use 1 or more of these implementations. A plugin is a sort of template or description that can be used in multiple different situations, rather than explicitly coding a single field or a single importer that is only used in one situation.
For example, if your module imports data into a Tripal site, you are most likely going to create an implementation of the Tripal Importer class rather than define your own plugin. A field is an example of a plugin created by someone else that you would want to implement. In order for your module to provide a custom Tripal field, then you are going to be implementing either the Tripal Field plugin or Chado Field plugin.
Although more complex than typical plugins, entities are fill a similar role in modules. Read more about Entities to help decide whether what you need to implement is an entity or a regular plugin.
- Additional Resources:
What is a service?
You can think of a service as a class providing a reusable component to other classes within your module or other extension modules. A class whose purpose is to provide an API is a great example of a service. Another example is pulling values from configuration settings. A service should only be used if you do not expect or support a site using multiple implementations of the same service. If you do, then you should create a plugin instead. That said, services are more lightweight than plugins and should be seriously considered as an option if you are trying decide between developing a new service or a plugin.
Some Tripal-specific services you may want to utilize in your extension module include:
Tripal Logger to handle error reporting and logging of messages to the system
Tripal Jobs for dealing with large datasets outside of a page load (to prevent page timeout)