Skip to content

Commit 075adc8

Browse files
committed
updates
1 parent 16a6d5f commit 075adc8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

singleton/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ id(OBJECT3) = 2164775087968
3535
Variables declared at class level are static variables that can be accessed directly using the class name without the class needing to be instantiated first.
3636

3737
**cls** is a reference to the class
38+
3839
**self** is a reference to the instance of the class
40+
3941
**\__new\__** gets called before **\__init\__**
42+
4043
**\__new\__** has access to class level variables
44+
4145
**\__init\__** references self which is created when the class is instantiated
4246

4347
By using **\__new\__**, and returning a reference to **cls**, we can force the class to act as a singleton. For a class to act as a singleton, it should not contain any references to **self**.

0 commit comments

Comments
 (0)