namespace AbstractEx
{
abstract class Book
{
private static int isbn = 0;
public string ISBN
{
get
{
return String.Format("{0:d4}", isbn++);
}
}
// ์ถ์ ํ๋กํผํฐ => ๊ตฌํ์ด ์๋ ํ๋กํผํฐ abstract๊ฐ ๋ถ์ด์๊ธฐ ๋๋ฌธ์
abstract public DateTime BookDate
{
get;set;
}
}
class MyBook : Book
{
public override DateTime BookDate
{
get;
set;
}
}
class Program
{
static void Main(string[] args)
{
Book book1 = new MyBook()
{
BookDate = new DateTime(2015, 10, 10),
};
Book book2 = new MyBook()
{
BookDate = new DateTime(2017, 7, 7),
};
Console.WriteLine($"Book : {book1.ISBN}, PublishDate : {book1.BookDate}");
Console.WriteLine($"Book : {book2.ISBN}, PublishDate : {book2.BookDate}");
}
}
}
Output
Book : 0000, PublishDate : 2015-10-10 ์ค์ 12:00:00
Book : 0001, PublishDate : 2017-07-07 ์ค์ 12:00:00
- ์ถ์ ํด๋์ค ๋ด ์ถ์๋ฉ์๋ ๋ํ ์๋ ํ๋กํผํฐ ์ฌ์ฉ์์ ์ ์ํด์ผํ๋ค.
abstract
ํค์๋๊ฐ ๋ถ์ ์ถ์๋ฉ์๋๋ ์๋ ํ๋กํผํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๊ตฌํ๋ถ๊ฐ ์๊ธฐ ๋๋ฌธ์ ์์๋ฐ๋ ํด๋์ค์์ ํด๋น ์ถ์๋ฉ์๋๋ฅผ override
ํ์ฌ ์ฌ์ฉํด์ผํ๋ค.
- ์ด๋ ์ธํฐํ์ด์ค์์์ ์๋ ํ๋กํผํฐ ๋ฉ์๋
override
์ ์ ์ฌํ๋ค.