Skip to content

Commit cd090a0

Browse files
authored
Merge pull request #11 from WeihanLi/main
enhancement on Caching singletons sample code
2 parents afd09a7 + 28344e7 commit cd090a0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

1.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public class Factory
198198

199199
private static class Cache<T>
200200
{
201-
public static T Instance = new T();
201+
public static readonly T Instance = new T();
202202
}
203203
}
204204
```
@@ -215,9 +215,9 @@ public class Factory
215215

216216
private static class Cache<T>
217217
{
218-
public static T Instance = CallExpensiveMethodToBuildANewInstance();
218+
public static readonly T Instance = CallExpensiveMethodToBuildANewInstance();
219219

220-
public static T CallExpensiveMethodToBuildANewInstance()
220+
private static T CallExpensiveMethodToBuildANewInstance()
221221
{
222222
// Imagine a really complex process to construct T
223223
return instance.

0 commit comments

Comments
 (0)