C# 0 The Complete Reference


PART I C h a p t e r   2



Download 4,07 Mb.
Pdf ko'rish
bet51/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   47   48   49   50   51   52   53   54   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   2 :  

A n   O v e r v i e w   o f   C #  

13

PART IPART I



The same principle can also apply to programming. For example, consider a 

stack

(which is a first-in, last-out list). You might have a program that requires three different 

types of stacks. One stack is used for integer values, one for floating-point values, and one 

for characters. In this case, the algorithm that implements each stack is the same, even 

though the data being stored differs. In a non-object-oriented language, you would be 

required to create three different sets of stack routines, with each set using different names. 

However, because of polymorphism, in C# you can create one general set of stack routines 

that works for all three specific situations. This way, once you know how to use one stack, 

you can use them all.

More generally, the concept of polymorphism is often expressed by the phrase “one 

interface, multiple methods.” This means that it is possible to design a generic interface to 

a group of related activities. Polymorphism helps reduce complexity by allowing the same 

interface to be used to specify a 

general class of action.

 It is the compiler’s job to select the 



specific action

 (that is, method) as it applies to each situation. You, the programmer, don’t 

need to do this selection manually. You need only remember and utilize the general interface.

Inheritance

Inheritance

 is the process by which one object can acquire the properties of another object. 

This is important because it supports the concept of hierarchical classification. If you 

think about it, most knowledge is made manageable by hierarchical (that is, top-down) 

classifications. For example, a Red Delicious apple is part of the classification 

apple,

 which 


in turn is part of the 

fruit

 class, which is under the larger class 



food.

 That is, the 



food

 class 


possesses certain qualities (edible, nutritious, and so on) which also, logically, apply to its 

subclass,



fruit.

 In addition to these qualities, the 



fruit

 class has specific characteristics (juicy, 

sweet, and so on) that distinguish it from other food. The 

apple

 class defines those qualities 

specific to an apple (grows on trees, not tropical, and so on). A Red Delicious apple would, 

in turn, inherit all the qualities of all preceding classes and would define only those qualities 

that make it unique.

Without the use of hierarchies, each object would have to explicitly define all of its 

characteristics. Using inheritance, an object need only define those qualities that make it 

unique within its class. It can inherit its general attributes from its parent. Thus, the 

inheritance mechanism makes it possible for one object to be a specific instance of a more 

general case.




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   47   48   49   50   51   52   53   54   ...   1096




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