I'm working on project on IntelliJ IDEA
and I want to add support to Extensible Applications in my java application.
The way to do it is, creating a jar file in this jar file there should be a META-INF/services directory, inside this directory, I need to add a file whose name contains the same name as the fully-qualified name of the interface which provides the service, and in that file it should have the fully-qualified name of the implementations of that interface.
This is the encrypt and decrypt service in my project .
These two are the files in my program which provides the service.
This is the interface which declares the service methods.
package serviceLoader;
public interface Cipher {
byte[] encrypt(byte[] source, byte[] key);
byte[] decrypt(byte[] source, byte[] key);
int strength();
}
This is the implementation class for those services.
package serviceLoader.impl;
import serviceLoader.Cipher;
public class CaesarCipher implements Cipher {
public byte[] encrypt(byte[] source, byte[] key) {
var result = new byte[source.length];
for (int i = 0; i < source.length; i++)
result[i] = (byte)(source[i] + key[0]);
return result;
}
public byte[] decrypt(byte[] source, byte[] key) {
return encrypt(source, new byte[] { (byte) -key[0] });
}
public int strength() {
return 1;
}
}
I want to know how to create this program according to a singleton-design pattern, and do I need any additional java files to to achieve singleton-design pattern?