У меня есть базовый абстрактный класс Goods
и унаследованный класс Book
.
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);
}
}
Должен ли я писать title
, barCode
, price
, которые существуют в классе Goods
дважды? Могу ли я заменить этот
public Book(string title, string barCode, double price, int numPages)
: base(title, barCode, price)
с менее избыточной конструкцией?