0
我試圖將裝飾模式應用於將一個單詞加密成某種加密的對象,如L337方法,它用g替換字母9,或用r替換4 。基本上,我想在輸入字段中輸入一個單詞並在文本對象中顯示加密的單詞。但是我不能讓L337裝飾器從主裝飾器類繼承。它不會接受關鍵字'super',所以我嘗試了基本詞,但是當我實現Encrypt時,它不會接受newEncryption對象。有人可以幫我弄清楚如何把這種模式放在一起嗎?使用裝飾模式統一加密字符串
我基本知道裝飾模式是什麼。它正在製作一個對象,製作一個基本的裝飾器,並製作一個特定的裝飾器,並用裝飾來實例化對象以獲得獨有的方法和特性。
public class Encryption : MonoBehaviour
{
public static InputField inputBox;
public static Text outputText;
public interface IEncryption { void Encrypt(); }
public class TextEncryption : IEncryption
{
public void Encrypt()
{
string currentText = inputBox.text;
outputText.text = currentText;
}
}
public abstract class encryptionDecorator : IEncryption
{
protected IEncryption tempEncryption;
public encryptionDecorator(IEncryption newEncryption)
{
tempEncryption = newEncryption;
}
public void Encrypt()
{
tempEncryption.Encrypt();
}
}
public class L337EncryptionDecorator : encryptionDecorator
{
public L337EncryptionDecorator(IEncryption newEncryption) : base(newEncryption)
{
print("Encrypting L337 Code");
}
public void Encrypt()
{
}
}
}