2011-07-22 12 views
0

アイテムのクラスを作成する必要がありますか?抽象クラスを使って作成する予定でした。したがって、ストア、購入、BOMのような他のクラスでもアイテムを使用できます。 ItemName、ItemDesc、ItemMakeなどのAbstactクラスでいくつかのメソッドを作成する必要があります。これを他のクラスでも使用できるように、どうすればよいですか?アイテムの抽象クラスを作成する必要があります

+0

あなたはまた、インターフェースを見てみることをお勧めします。 microsoft.com/en-us/library/ms173156.aspx –

+2

「ItemName」、「ItemDesc」のようなプロパティ名を付けることをお勧めします。代わりに 'Name'、' Description'などと呼ぶべきです。 –

答えて

1

あなたはより詳細な情報については、MSDNでオーバーに見えますが、ここではモック簡単です必要があります。http:// MSDN

public abstract class BaseItem 
{ 
    public int ItemId{get;set;} 
    public string ItemName{get;set;} 
    /* Add additional properties */ 

    public void PublichSharedMethod() 
    { 
     /* This method will be publicly available to all derived members and external activators */ 
    } 

    protected void PortectedMethod() 
    { 
     /* This method will be available only to derived classes */ 
    } 

    protected virtual ProtectedBaseImplementation() 
    { 
     /* This method will be available only to derived classes, and they can override its behavior */ 
    } 

    public abstract void RequriesImplementation(); 
     /* This method is publicly available to all, but all derived classes must implement it */ 

} 
+1

RequriesImplementationは抽象的であるため実際にはボディを持つことはできません – DanNsk

+0

You'r right私は他のものからコピー&ペーストして削除するのを忘れました...ありがとう! – sternr

関連する問題