This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


The Third Pillar: C#’s Polymorphic Support



Download 21,46 Mb.
Pdf ko'rish
bet408/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   404   405   406   407   408   409   410   411   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

The Third Pillar: C#’s Polymorphic Support

Recall that the Employee base class defined a method named GiveBonus(), which was originally

implemented as follows:

public partial class Employee

{

public void GiveBonus(float amount)



{

currPay += amount;

}

...


}

Because this method has been defined with the public keyword, you can now give bonuses to

salespeople and managers (as well as part-time salespeople):

static void Main(string[] args)

{

Console.WriteLine("***** The Employee Class Hierarchy *****\n");



// Give each employee a bonus?

Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

chucky.GiveBonus(300);

chucky.DisplayStats();

Console.WriteLine();

SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

fran.GiveBonus(200);

fran.DisplayStats();

Console.ReadLine();

}

The problem with the current design is that the publicly inherited GiveBonus() method oper-



ates identically for all subclasses. Ideally, the bonus of a salesperson or part-time salesperson

should take into account the number of sales. Perhaps managers should gain additional stock

options in conjunction with a monetary bump in salary. Given this, you are suddenly faced with an

interesting question: “How can related types respond differently to the same request?” Glad you

asked!


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   404   405   406   407   408   409   410   411   ...   1830




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish