"Egyke tervminta" "Ebben a példában egy adatbáziskezelő osztályt valósítunk, melyből csak egyetlen egy létezhet. Az írások és az olvasások között zárolást használ az osztály." Object subclass: #DatabaseAccessor instanceVariableNames: 'lock' classVariableNames: 'Instance' poolDictionaries: '' DatabaseAccessor class>>singleton Instance isNil ifTrue: [Instance := self basicNew initialize]. ^Instance DatabaseAccessor class>>new ^self error: 'DatabaseAccessor has only one instance. ','To retrieve it, send "DatabaseAccessor singleton".' DatabaseAccessor>>initialize lock := false. "Open the file" DatabaseAccessor>>write: aDatabaseRecord "Set the lock and fork the 'real' write method." lock := true. [self writePrim: aDatabaseRecord] fork DatabaseAccessor>>writePrim: aDatabaseRecord "Write the record in aDatabaseRecord to the file." "Now that the write is complete, unlock:" lock := false. DatabaseAccessor>>read: aKey "Return the DatabaseRecord keyed by aKey." | record | "Don't read while a write is in progress." [lock] whileTrue: [Processor yield]. "Now, read the record:" record := DatabaseRecord new. "Modify the Record" ^record “DatabaseAccessor singleton read: aKey” “DatabaseAccessor default.”