從非抽象類派生抽象類還是出現這種方法有什麼問題?從非抽象類派生抽象類
Here's一個小例子:
public class Task {
// Some Members
}
public abstract class PeriodicalTask : Task {
// Represents a base class for task that has to be done periodicaly.
// Some additional Members
}
public class DailyTask : PeriodicalTask {
// Represents a Task that has to be done daily.
// Some additional Members
}
public class WeeklyTask : PeriodicalTask {
// Represents a Task that has to be done weekly.
// Some additional Members
}
在上面,我不想讓類任務抽象的,因爲我想直接實例它的例子。 PeriodicalTask應該繼承Task中的功能並添加一些額外的成員,但我不想直接實例化它。只有派生類的PeriodicalTask應該被實例化。
完美實例Dan – 2010-04-08 19:29:12
良好示例因此接受 – Jehof 2010-04-09 06:01:21
哇!真的,很好的例子。 – ManuelSchneid3r 2012-12-07 11:31:36