Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet191/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   187   188   189   190   191   192   193   194   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
283 
asRExp 
^ self 
The asRExp operation will convert literals intoRegularExpressions. These 
operations are defined in classString: 
& aNode 
^ SequenceExpression new 
expression1: self asRExp expression2: aNode asRExp 
repeat 
^ RepetitionExpression new repetition: self 
| aNode
^ AlternationExpression new 
alternative1: self asRExp alternative2: aNode asRExp 
asRExp 
^ LiteralExpression new components: self 
If we defined these operations higher up in the class 
hierarchy(SequenceableCollection in Smalltalk-80,IndexedCollection in 
Smalltalk/V), then they wouldalso be defined for classes such as Array 
andOrderedCollection. This would letregular expressions match sequences of any 
kind of object. 
The second example is a system for manipulating and evaluatingBoolean expressions 
implemented in C++. The terminal symbols in thislanguage are Boolean variables, 
that is, the constantstrue and false. Nonterminal symbols representexpressions 
containing the operators and, or, andnot. The grammar is defined asfollows
1

BooleanExp ::= VariableExp | Constant | OrExp | AndExp | NotExp | 
'(' BooleanExp ')' 
AndExp ::= BooleanExp 'and' BooleanExp 
OrExp ::= BooleanExp 'or' BooleanExp 
NotExp ::= 'not' BooleanExp 
Constant ::= 'true' | 'false' 
VariableExp ::= 'A' | 'B' | ... | 'X' | 'Y' | 'Z' 
We define two operations on Boolean expressions. The first,Evaluate, evaluates 
a Boolean expression in a contextthat assigns a true or false value to each variable. 
The secondoperation, Replace, produces a new Boolean expression byreplacing a 
variable with an expression. Replace showshow the Interpreter pattern can be used 
for more than just evaluatingexpressions. In this case, it manipulates the 
expression itself. 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   187   188   189   190   191   192   193   194   ...   288




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