Ich habe Basis abstrakt Goods
Klasse und vererbt Book
Klasse.Abstrakte Klassenfelder Redundanz C#
abstract class Goods
{
public decimal weight;
string Title, BarCode;
double Price;
public Goods(string title, string barCode, double price)
{
Title = title;
BarCode = barCode;
Price = price;
}
}
abstract class Book : Goods
{
protected int NumPages;
public Book(string title, string barCode, double price, int numPages)
: base(title, barCode, price)
{
NumPages = numPages;
weight = 1;
}
public override void display()
{
base.display();
Console.WriteLine("Page Numbers:{0}", NumPages);
}
}
Soll ich schreiben title
, barCode
, price
, die zweimal in der Goods
Klasse existieren? Kann ich das ersetzen
public Book(string title, string barCode, double price, int numPages)
: base(title, barCode, price)
mit weniger redundante Konstruktion?
Nur eine Anmerkung. Sie haben ** Felder ** und nicht ** Eigenschaften **. Eigenschaften sollten 'get' und/oder' set' haben. –
Bitte verwenden Sie 'decimal' (oder Integer) anstelle von' double', um Preise darzustellen. – CodesInChaos
Ich würde überlegen, die abstrakte Klasse durch eine Schnittstelle zu ersetzen. – CodesInChaos