Microsoft Word OpenIssuesInOO. doc


  Genericity and virtual classes



Download 1.28 Mb.
Pdf ko'rish
bet24/51
Sana29.08.2021
Hajmi1.28 Mb.
1   ...   20   21   22   23   24   25   26   27   ...   51
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 2020
ma'muriyatiga murojaat qiling

    Bosh sahifa
davlat universiteti
ta’lim vazirligi
maxsus ta’lim
O’zbekiston respublikasi
zbekiston respublikasi
axborot texnologiyalari
o’rta maxsus
nomidagi toshkent
guruh talabasi
davlat pedagogika
texnologiyalari universiteti
xorazmiy nomidagi
toshkent axborot
pedagogika instituti
rivojlantirish vazirligi
haqida tushuncha
toshkent davlat
Toshkent davlat
vazirligi toshkent
tashkil etish
matematika fakulteti
ta’limi vazirligi
kommunikatsiyalarini rivojlantirish
samarqand davlat
vazirligi muhammad
pedagogika universiteti
bilan ishlash
fanining predmeti
Darsning maqsadi
navoiy nomidagi
o’rta ta’lim
Ishdan maqsad
haqida umumiy
nomidagi samarqand
fizika matematika
sinflar uchun
fanlar fakulteti
maxsus ta'lim
Nizomiy nomidagi
ta'lim vazirligi
moliya instituti
universiteti fizika
Ўзбекистон республикаси
umumiy o’rta
Referat mavzu
respublikasi axborot
Toshkent axborot
таълим вазирлиги
Alisher navoiy
махсус таълим
Buxoro davlat