Microsoft Word OpenIssuesInOO. doc


  Genericity and virtual classes



Download 1,28 Mb.
Pdf ko'rish
bet24/51
Sana29.08.2021
Hajmi1,28 Mb.
#158917
1   ...   20   21   22   23   24   25   26   27   ...   51
Bog'liq
OpenIssuesInOO

4.3 

Genericity and virtual classes 

One of the distinguishing features of BETA is the unification of abstraction mechanisms 

like class, procedure, function, etc. into one general abstraction mechanisms: the pattern. In 

the previous section we have discussed one aspect of patterns in the form of virtual 

procedure patterns. Virtual procedure patterns correspond to using virtual patterns as virtual 

functions in C++ or methods in Smalltalk. 

A virtual class pattern is a virtual pattern used as a class. Virtual class pattern is the 

BETA construct corresponding to class parameters of generic classes in Eiffel and template 

classes in C++.  Consider the following example: 

Set:  


 (# 

elm:< 


Object; 

 

 



R: [100] ^elm; top: @ integer 

   Insert: 

    (# 

E: 


^elm 

    enter 

E[] 

    do 


E[]-> 

R[top+1->top][] 

    #); 

   ... 


 #) 

The Set pattern has a virtual class pattern attribute, elm that is the pattern of elements to 

be inserted into the set. Since  elm is a virtual class pattern, it may be constrained in 

subpatterns of Set. In the above declaration it is constrained (or qualified) by the pattern 

Object. Since all patterns are subpatterns of Object, any pattern may be used for  elm. 

I.e. any object may be inserted into a Set object. The declaration of Set thus corresponds 

to an unconstrained generic class in Eiffel, or a template class in C++. 

In general pattern Set may be used as any other pattern in BETA, including as a super 

pattern: 

PersonSet: Set 

 (# 

elm::< 


Person; 


   Find: 

 

 



 

(# name: ^text; E: ^elm 

    enter 

name[] 


 

 

 



do {find an element E, where E.name=name} 

    exit 

E[] 

 

 



 

#) 


   ... 

 #) 


In pattern PersonSet, elm has been constrained to pattern Person. Consequently only  

instances of pattern Person may be inserted in a PersonSet. Within PersonSet, all 

references qualified by elm are known to refer to instances of at least pattern Person. I.e. 

it is possible to refer to Person attributes through such references. For example in pattern 

Find, the expression E.name is legal since E must refer to a Person object. 

Pattern  PersonSet corresponds to a constrained generic class in Eiffel. In C++ this 

kind of constrained genericity is not possible.  

It is generally agreed that some form of parameterised class mechanism is needed for 

statically-typed languages. C++ offers a simple form; Eiffel and BETA offer more advanced 

forms. Whether or not the differences between the approaches taken in the latter languages 

are important may be difficult to judge. In practice it seems that all three languages can 

express the same. However, there is a difference with respect to the definition of 

subclass/subtype/-conformance of such parameterised classes and in the handling of 

covariance and contravariance. The latter will be further discussed in section 4.6 below. For 

a further discussion of parameterised classes see Reference [MMM90]. 


Download 1,28 Mb.

Do'stlaringiz bilan baham:
1   ...   20   21   22   23   24   25   26   27   ...   51




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