2011-08-03 21 views
0

異なるメソッドごとに毎回説明をインスタンス化する必要はありますか?または私は静的を使用する必要がありますか?私は今これをやっています:このような状況を処理する最良の方法は何ですか?私はこの行を繰り返すようです:Dim description As BLLDescription = New BLLDescription()良いreasnなし。あなたは、静的クラスとしてBLLDescriptionを定義する場合異なるメソッドでクラスのインスタンスを作成する方法

Protected Sub Button8_Click(sender As Object, e As System.EventArgs) Handles Button8.Click 
      Dim description As BLLDescription = New BLLDescription() 
      List<String> = description.GetDescriptionWithoutNotes() 
      ..... 
     End Sub 

    Protected Sub Button9_Click(sender As Object, e As System.EventArgs) Handles Button9.Click 
     Dim description As BLLDescription = New BLLDescription() 
     List<String> = description.GetDescriptionWithNotes() 
     ..... 
    End Sub 
Protected Sub Button10_Click(sender As Object, e As System.EventArgs) Handles Button10.Click 
      Dim description As BLLDescription = New BLLDescription() 
      List<String> = description.GetAllDescriptions() 
      ..... 
     End Sub 

答えて

0

、あなたはインスタンス化することなく、GetAllDescriptions()メソッドを呼び出すことができます:それはBLLDescriptionのインスタンスが何をするかに依存し

Protected Sub Button8_Click(sender As Object, e As System.EventArgs) Handles Button8.Click 
      List<String> = BLLDescription.GetDescriptionWithoutNotes() 
      ..... 
     End Sub 

    Protected Sub Button9_Click(sender As Object, e As System.EventArgs) Handles Button9.Click 
     List<String> = BLLDescription.GetDescriptionWithNotes() 
     ..... 
    End Sub 
Protected Sub Button10_Click(sender As Object, e As System.EventArgs) Handles Button10.Click 
      List<String> = BLLDescription.GetAllDescriptions() 
      ..... 
     End Sub 
+0

わかりました。なぜ私はそのthoguhをしてはいけないのですか? – user194076

+0

データはBLLDescriptionのインスタンスごとに異なるものではなく、データアクセスレイヤーとしてのみ使用されるため、静的として宣言することが最も理にかなっています。 – hspain

0

、それが取得する方法データ。

同じデータに繰り返しアクセスしている場合は、静的と宣言できます。リクエストごとに同じデータが得られる場合は、それをクラスレベルのプロパティとして使用します。

+0

BLLDescriptionは、以下のようなaprametersを持つdataaccesレイヤーからFunctionを呼び出します。BllDescription.GetAllDescription(int number)。クラスレベルのプロパティではどういう意味ですか? – user194076

+0

そうです、それぞれの呼び出しでパラメータが変更された場合は、 'Page'クラスのどこか他の場所のプロパティとして使用してください。こうすることで、コンストラクタでインスタンス化して接続を開くことができ、 'GetAllDescriptions'の各呼び出しは同じオーバーヘッドを経る必要はありません。 – Mrchief

関連する問題