Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating reusable modules

I'm writing a big Red5 Java application for the web. Red5 a Flash Media Server alternative that is java based and is written with the spring framework.

I want to have many versions of my application online, each with different behaviors and different classes enabled or disabled.

I'm looking for a way to convert my code into modules based code that will allow me to remove/add modules/features from the main application.

I know about OSGI http://www.springsource.org/osgi but it says that it needs a SpringSource dm server and I have no idea how it's gonna work together in red5 and it's seems very complicated to fully understand.

I don't have a good knowledge of spring framework in general, i work with it db-related and that's it. red5 uses it more extensively.

so can anyone please make any sense from this information ? is there something that can be done to divide my code to modules ?

any information regarding the issue would be greatly appreciated.

like image 289
ufk Avatar asked Jul 26 '12 12:07

ufk


People also ask

What is reusable module?

Reusability is a generic term describing the degree to which a module can be shared, reused or replaced during execution. It incorporates the following attributes: Nonreusable. The module is designed for single use only and must be refreshed before it can be reused.

Can a module be reused?

In order for a module or package to be reusable, it has to meet the following requirements: It must function as a standalone unit. If your package is intended to be included as part of the source code for another system, you must use relative imports to load the other modules within your package.

How do you create a reusable code in Python?

And when it comes to reusing code in Python, it all starts and ends with the humble function. Take some lines of code, give them a name, and you've got a function (which can be reused). Take a collection of functions and package them as a file, and you've got a module (which can also be reused).

How do I create a .TF file?

Create a new folder called modules and move all the files (that is, main.tf , variables.tf , and outputs.tf ) from the web server cluster into modules/services/webserver-cluster . Open up the main.tf file in modules/services/webserver-cluster and remove the provider definition.


1 Answers

My preferred method of dealing with this kind of situation is Dependancy Injection (DI). Spring has a DI capability built in, for which a tutorial is easy to find online. However, Spring's DI is not as good, for many reasons, as that provided by Guice, which I would highly recommend. (The main advantage of Guice over Spring's DI in my opinion is type safety.)

DI is basically a mechanism for replacing class implementations at runtime. Rather than hard code dependancies into classes (by having a class construct other classes directly for example) you code them to have their dependant classes passed to them in their constructors. The DI framework will then pass the correct instances at runtime according to the configuration. Spring configuration can be done via annotations or an XML file, Guice uses a subclass of com.google.inject.AbstractModule.

So you could use different configuration files for the different instances of your application, and have them provide different sets of features for activation, or indeed different implementations of the same feature. If you set up the application to use this technique then the only thing that need differ between instances is a single configuration file.

like image 74
Vic Smith Avatar answered Sep 19 '22 17:09

Vic Smith