I am designing a KeyPair interface which looks something like this,
public interface KeyPair {
@Deprecated
public Key firstKey();
@Deprecated
public Key secondKey();
}
I want to use this interface to implement two classes, PasswordEncryptionKeyPair
, PrivatePublicKeyPair
. But the problem is that I don't want to use the methods firstKey()
and secondKey()
as they are very generic. I rather want to use some other method and make these two method private. My current implementation is like this,
class PrivatePublicKeyPair implements KeyPair{
public Key getPrivateKey() {
return firstKey();
}
public Key getPublicKey() {
return secondKey();
}
@Override
public Key firstKey() {
return privateKey;
}
@Override
public Key secondKey() {
return publicKey;
}
}
As an interface cannot have private method I can't make the methods private. One way this is possible is by adding body in the interface itself or create an AbstarctKeyPair
class, and make methods private there. Is there any other solution for this problem?
Aucun commentaire:
Enregistrer un commentaire