You are on page 1of 2

www.cz-milka.

net
2004-11-03
Programovací techniky:

ü Systém tříd Collection:


Collection allSubsclasses size > 80

Název třídy Tvorba instance Typ elementů Uspořádání Přístup


Bag new Object Není Hodnotou
Array new: aNumber Object 1 .. size Indexem
String new: aNumber Character 1 .. size Indexem
Text aString asText Character 1 .. size Indexem
ByteArray new: aNumber SmallInteger 1 .. size Indexem
Interval aValue to:by: ArithmeticValue 1 .. size Indexem
OrderedCollection new Object First .. last Indexem
SortedCollection new Mognitude Pravidlem Indexem
Set new Object Není Hodnotou
Dictionary new Object Není Klíčem

asSet, asOrderedCollection, asArray, asSortedColleciton, …

ByteArray with: 12 with: 34 #[12 34]


String with: $a with: $b with: $c ‘abc’

ü Systém tříd Collection – příklady:


Třída List – umí totéž co OrderedCollection a SortedCollection

X := OrderedCollection with: 12 with: 34 with 15


X addLast: 56. X addFirst: 17.
X removeFirst.
%(1 2 3 5 7) reverse. ‘hello world’ reverse

│y│
y := %(1 2 6 5 3) asSortedCollection.
y add: 4.
^y

│y│
y := %(1 2 -6 -3) asSortedCollection: (:a :b │a abs > b abs).
y add: 4.
^y

│d│
d := Dictionary new.
D at: ‘Jan’ put: ’54 23 30’
at: ‘Iveta’ put: ’35 44 40’
at: ‘Milan’ put: ’338 2274’
^ d at: ‘Iveta’

ü Operace nad sadami (Collecions):


• Iterace před všechny prvky:
%(12 34 56 78) do: [:i │ Transcript show: I printString; cr]
((1 to: 10), §(12 15)) do: [:n│Trsrpt show: n printString; cr]
• Selekce – výběr:
%(1 5 2 4 3) select: [:x│ x > 2] %(5 4 3)
‘hello world’ select: [:ch│ch isVowel] ‘eoo’
• Rejekce
www.cz-milka.net
%(1 5 2 4 3) reject: [:ch│ch isVowel] ‘hll wrld’

• Kolekce – transformace, změna


%(1 5 2 4 3) collect: [:x│ x + 10] %(11 15 12 14 13)
• Detekce
%(1 5 2 4 3) detect: [:x│ x > 2] 5
• Injekce
%(1 5 2 4 3) inject: 0 into: [:x :y│ x + y] 15
%(1 5 2 4 3) inject: 1 into: [:x :y│ x * y] 120

ü Závislost objektů – Value Holders:


Value: anObject
ValueHolder
Value
Value/anObject
anObject

SelectionInList list
list: aList
listHolder/ValueModel selection
selectionIndexHolder/ValueModel selection: anObjectOrCollection

SelectionTable table
table: aTableAdaptorOrTwoDList
listHolder/ValueModel selection
selectionIndexHolder/ValueModel selection: anObject

Adaptory:
• Adaptory jsou objekty, které vytvářejí jednotná rozhraní jiným objektům. Pomocí adaptorů lze stejným
způsobem používat různé objekty s různými protokoly.
• Adaptory jsou polymorfní s ValueHoldery (pro zprávy value a value:)
• AspektAdaptor:
Vytvoření Nastavení
AspectAdaptor accessWith: getSymbol
Subjekt: anObject assignWith: putSymbol (není-li použito, tak platí nastavení %value: a %value)
• PluggableAdaptor:
Vytvoření Nastavení
PluggableAdaptor getBlock: aBlock (:model)
on: anObject putBlock: aBlock (:model :value)
updateBlock: aBlock (^true│^false)

You might also like