例えば:静的メソッドを持つクラスを持っていますか?そのすべてが同じプロパティを持ち、悪いとみなされますか?
class A
{
...
//class variables and methods
public static A GetAWithKey (DatabaseConnection conn, string key) {...}
public static A[] GetSomeAWithKeys (DatabaseConnection conn, string keys[]) {...}
public static bool IsAWithThisPropertyExists (DatabaseConnection conn, string thisProperty) {...}
}
問題である - それらの全ては、私は、コード内のすべてのメソッド呼び出しに渡すDatabaseConnectionの同じインスタンスを動作します。
DatabaseConnectionをクラスAの静的変数にするのは賢明ですが、正しく初期化するにはどうすればいいですか?それとも別の良い解決策がありますか?
「シングルトンパターン」を使用 – Xaqron
@Xaqronどのように理解できないのですか、コード例で明確にすることはできますか? –
このリンクをチェック:http://csharpindepth.com/Articles/General/Singleton.aspx – Xaqron