| ||
Student Originated Software 1997-1998
| ||
A Software Engineering Course at The Evergreen State College | ||
|
Student Originated SoftwareObject-Oriented Programming (Smalltalk)Dated: October 10, 1997Lecture 4a(review the solutions? email them out....)
------
ifTrue: [...]. whileTrue: [x:= x+1]. ...look at the definition of whileTrue myArray size repeatTimes: [....]
magnitude - consider (subclass Responsibility), and >= implemented in terms of >
Number Hierarchy......
consider arithmetic value .... why are almost all the arithmetic functions implemented by subclass Responsibility, while some of the testing and comparison functions can be directly implemented?
look at double dispatching..... see arithmetic operations in fixedpoint, fraction and integer.....
Ch. 14 -- Unordered Collections....
interesting things to peruse in collections....
class hierarchy for collection.... look at comment field! accessing, testing, adding, enumerating....
unordered collections - set, class, bag.
creating and adding... | mySet | mySet := (Set with:2 with:3 ) addAll: (Set with: 4 with:5). does NOT produce Set(2,3,4,5) mySet.
| mySet | mySet := (Set with:2 with:3 ). mySet addAll: (Set with: 4 with:5). mySet.
-----
| mySet | mySet := Set with: 2 with: 3. mySet add: 5. mySet. mySet add: (Set with: 'a').
mySet -----
| mySet | mySet := Set with: 2 with: 3. mySet add: 5. mySet. mySet add: (Set with: 'a' with: 'b'). mySet addAll: (Set with:'c' with:'d').
mySet
-----
remove: remove: ifAbsent:
----
set := Set new. set add: 'a'. set add: '5. set. set addAll: (Set with:1 with:3 with:4). set. set - (Set with:'a' with:'b' with:'c').
----
occurrencesOf: size
------
isEmpty includes:
-----
set enumeration!
(Set with: 1 with: 3 with:4) collect: [:each | each factorial]
(Set with: 1 with: 3 with:4) collect: [:each | each factorial] Set (1 24 6) (Set with: 1 with: 3 with:4) collect: [:each | each > 3] Set (false true) (Set with: 1 with: 3 with:4) select: [:each | each >3] Set (4) (Set with: 1 with: 3 with:4) select: [:each | each >4] Set () (Set with: 1 with: 3 with:4) reject: [:each | each >3] Set (3 1) (Set with: 1 with: 3 with:4) detect: [:each | each >3] 4
(Set with: 1 with: 5 with:4) inject:0 into:[:sum :each | sum + each] 10
(Set with: 1 with: 5 with:4) inject:0 into:[:max :each | max max: each] 5
(Set with: 1 with: 5 with:4) do: [:each | Transcript show: each factorial printString; cr] 1, 24, 120
(Set with: 65 with: 66 with:67) do: [:each | Transcript show: each asCharacter printString; cr] $A $B $C
------------
Dictionaries -- association lists
| myDict | myDict := Dictionary new. myDict at: 'hemlock' put: 'hemlockus'. myDict at: 'spruce' put: 'sprucus'. myDict. Dictionary ('spruce'->'sprucus' 'hemlock'->'hemlockus' )
--------- keys values associationAt: keyAtValue: ------
removeKey: removeKey: ifAbsent:
includesKey:
do: keysDo: keysAndValuesDo:
----------
Object identity (==) vs. object equality (=)
copy, shallow copy, deep copy.....
IdentityDictionary is more efficient than Dictionary. why?
--------
Sequenceable Collections. (e.g., array)
arrays are fixed in size, and cannot grow.
do: [] reverseDo: [] , reverse findFirst: [:i | i>3] findLast: replaceFrom: to: with:
OrderedCollection. add: addFirst: adLast: add:after: add:before: addAllFirst: addAllLast:
after: before:
SortedCollection classvariable - DefaultSortBlock := [:x :y | x &= y] gives ascending order (any object that understands &=)
Assignment for Chapter 15 -- 15.2 - Build a binary tree class Optional - 15.3, 15.4
Assignment for Chapter 15 -- 15.6, 15.12, 15.13.
In Lab, also do: 15.5 -----
string manipulation symbols --
'abc' = 'abc' 'abc' ~== 'abc' #abc = #abc
[ SOS Home Page | Case Study | Year Long Projects | OOP ]
|