2022-02-15 18:04:54 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaSingleton,
|
|
|
|
#superclass : #DiyaBaseObject,
|
|
|
|
#classVars : [
|
|
|
|
'singletons'
|
|
|
|
],
|
|
|
|
#category : #'Diya-Core'
|
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaSingleton class >> cleanUpInstance: singleton [
|
|
|
|
"do nothing for now"
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'class initialization' }
|
|
|
|
DiyaSingleton class >> initialize [
|
|
|
|
singletons := Dictionary new.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaSingleton class >> new [
|
2022-03-19 02:18:29 +01:00
|
|
|
^ DiyaCoreAPIError signal: 'Use #uniqueInstance'
|
2022-02-15 18:04:54 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaSingleton class >> reset [
|
2022-03-15 19:11:19 +01:00
|
|
|
|singleton key|
|
|
|
|
key := self class asString asSymbol.
|
|
|
|
singleton := singletons at: key ifAbsent: [ ^ self ].
|
2022-02-15 18:04:54 +01:00
|
|
|
self cleanUpInstance: singleton.
|
2022-03-15 19:11:19 +01:00
|
|
|
singletons removeKey: key
|
2022-02-15 18:04:54 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaSingleton class >> uniqueInstance [
|
2022-03-15 19:11:19 +01:00
|
|
|
^singletons at: self class asString asSymbol ifAbsentPut: [ super new ].
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaSingleton >> initialize [
|
|
|
|
super initialize.
|
|
|
|
Transcript show: 'Initialise unique instance of ', self className; cr.
|
2022-02-15 18:04:54 +01:00
|
|
|
]
|