【发布时间】:2009-03-29 16:31:50
【问题描述】:
AndroMDA 使用术语“墨盒”(例如,用于开箱即用的 NHibernate 支持)。 据我了解,它需要一个 API/组件,包装它,从不添加新功能,简化它,通常会带走“全部功能”,但适用于大多数情况。
我的问题:
这个词被广泛使用了吗?
可以正确定义吗?
是否应在类/方法名称中使用后缀“Cartridge”?
一个例子:下面的 Base64 助手是 Base64 转换的墨盒吗? 您放弃了性能调整的所有功能,但如果您只是想解码一个简单(和小)的字符串,它可以正常工作:
用法:
Base64StringCartridge.Decode(input);
实施
public static string Decode(string data)
{
try
{
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = System.Convert.FromBase64String(data);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result;
}
catch
{
return "";
}
}
【问题讨论】:
标签: naming-conventions design-patterns