|
| 1 | +" |
| 2 | +I am a contact book. I hold a list of contacts. |
| 3 | +" |
| 4 | +Class { |
| 5 | + #name : #CmContactBook, |
| 6 | + #superclass : #Object, |
| 7 | + #instVars : [ |
| 8 | + 'contents' |
| 9 | + ], |
| 10 | + #classInstVars : [ |
| 11 | + 'family', |
| 12 | + 'coworkers' |
| 13 | + ], |
| 14 | + #category : #'Commander2-ContactBook-Model' |
| 15 | +} |
| 16 | + |
| 17 | +{ #category : #accessing } |
| 18 | +CmContactBook class >> coworkers [ |
| 19 | + ^coworkers ifNil: [ |
| 20 | + coworkers := self new |
| 21 | + add: 'Stef' phone: '112 378'; |
| 22 | + add: 'Pavel' phone: '898 678'; |
| 23 | + add: 'Marcus' phone: '444 888'; |
| 24 | + yourself] |
| 25 | +] |
| 26 | + |
| 27 | +{ #category : #accessing } |
| 28 | +CmContactBook class >> family [ |
| 29 | + ^family ifNil: [ |
| 30 | + family := self new |
| 31 | + add: 'John' phone: '342 345'; |
| 32 | + add: 'Bill' phone: '123 678'; |
| 33 | + add: 'Marry' phone: '789 567'; |
| 34 | + yourself] |
| 35 | +] |
| 36 | + |
| 37 | +{ #category : #accessing } |
| 38 | +CmContactBook class >> reset [ |
| 39 | + <script> |
| 40 | + coworkers := nil. |
| 41 | + family := nil |
| 42 | +] |
| 43 | + |
| 44 | +{ #category : #accessing } |
| 45 | +CmContactBook >> add: contactName phone: phone [ |
| 46 | + | contact | |
| 47 | + contact := CmContact named: contactName phone: phone. |
| 48 | + self addContact: contact. |
| 49 | + ^contact |
| 50 | +] |
| 51 | + |
| 52 | +{ #category : #accessing } |
| 53 | +CmContactBook >> addContact: aContact [ |
| 54 | + contents add: aContact |
| 55 | +] |
| 56 | + |
| 57 | +{ #category : #accessing } |
| 58 | +CmContactBook >> addContact: newContact after: contactAfter [ |
| 59 | + contents add: newContact after: contactAfter |
| 60 | +] |
| 61 | + |
| 62 | +{ #category : #accessing } |
| 63 | +CmContactBook >> contents [ |
| 64 | + ^ contents |
| 65 | +] |
| 66 | + |
| 67 | +{ #category : #accessing } |
| 68 | +CmContactBook >> contents: anObject [ |
| 69 | + contents := anObject |
| 70 | +] |
| 71 | + |
| 72 | +{ #category : #testing } |
| 73 | +CmContactBook >> includesContact: aContact [ |
| 74 | + ^ contents includes: aContact |
| 75 | + |
| 76 | +] |
| 77 | + |
| 78 | +{ #category : #initialization } |
| 79 | +CmContactBook >> initialize [ |
| 80 | + super initialize. |
| 81 | + contents := OrderedCollection new. |
| 82 | +] |
| 83 | + |
| 84 | +{ #category : #accessing } |
| 85 | +CmContactBook >> removeContact: aContact [ |
| 86 | + contents remove: aContact |
| 87 | +] |
0 commit comments