Skip to content

Commit 2b07dee

Browse files
committed
Update lazy load pattern examples
1 parent 1fe67e9 commit 2b07dee

File tree

15 files changed

+31
-37
lines changed

15 files changed

+31
-37
lines changed

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/Executor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ public override void Execute()
1717
ValueHolderExecutor.Execute();
1818
VirtualProxyExecutor.Execute();
1919
}
20-
}
20+
}

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/GhostsExample/DomainObject.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ protected DomainObject(int id)
99
Id = id;
1010
}
1111

12-
public int Id { get; set; }
13-
12+
public int Id { get; init; }
1413
public bool IsGhost => _status == LoadStatus.Unloaded;
15-
1614
public bool IsLoaded => _status == LoadStatus.Loaded;
1715

1816
/// <summary>

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/GhostsExample/GhostCollege.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
/// </summary>
1111
public class GhostCollege : DomainObject
1212
{
13-
private string _missionStatement;
14-
private int _numberOfStudents;
15-
private Library _library;
13+
private string? _missionStatement;
14+
private int? _numberOfStudents;
15+
private Library? _library;
1616

1717
public GhostCollege(int id)
1818
: base(id)
@@ -26,7 +26,7 @@ public string MissionStatement
2626
get
2727
{
2828
LoadIfNecessary();
29-
return _missionStatement;
29+
return _missionStatement!;
3030
}
3131
set => _missionStatement = value;
3232
}
@@ -36,7 +36,7 @@ public int NumberOfStudents
3636
get
3737
{
3838
LoadIfNecessary();
39-
return _numberOfStudents;
39+
return _numberOfStudents!.Value;
4040
}
4141
set => _numberOfStudents = value;
4242
}
@@ -46,7 +46,7 @@ public Library Library
4646
get
4747
{
4848
LoadIfNecessary();
49-
return _library;
49+
return _library!;
5050
}
5151
set => _library = value;
5252
}
@@ -73,4 +73,4 @@ protected override void ApplyLoadedData(object[] dataRow)
7373
_numberOfStudents = (int)dataRow[1];
7474
_library = (Library)dataRow[2];
7575
}
76-
}
76+
}

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/GhostsExample/GhostsExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ public static void Execute()
1818
Console.WriteLine("\nGive me more details about the college!");
1919
college.ShowDetails();
2020
}
21-
}
21+
}

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/GhostsExample/LoadStatus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ public enum LoadStatus
55
Unloaded,
66
Loading,
77
Loaded,
8-
}
8+
}

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/LazyInitializationExample/LazyCollege.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class LazyCollege
44
{
5-
private Library _library;
5+
private Library? _library;
66

77
public Library Library
88
{

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/LazyInitializationExample/LazyInitializationExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ public static void Execute()
1616
Console.WriteLine("\nGive me more details about the college!");
1717
dotNetCollege.ShowDetails();
1818
}
19-
}
19+
}

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/Library.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ public Library()
1212
NumberOfBooks = 10000;
1313
}
1414

15-
public string Name { get; set; }
16-
17-
public DateTime EstablishmentDate { get; set; }
18-
19-
public string Address { get; set; }
20-
21-
public int NumberOfBooks { get; set; }
22-
}
15+
public string Name { get; }
16+
public DateTime EstablishmentDate { get; }
17+
public string Address { get; }
18+
public int NumberOfBooks { get; }
19+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace LazyLoadLibrary.ValueHolderExample;
22

3-
public interface IValueLoader<T>
3+
public interface IValueLoader<out T>
44
{
55
T Load();
6-
}
6+
}

src/AdditionalPatterns/LazyLoad/LazyLoadLibrary/ValueHolderExample/ValueHolder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
/// <summary>
44
/// A value holder is a generic object that handles the lazy loading behavior
5-
/// and appears in place of the objects data fields.
5+
/// and appears in place of the object's data fields.
66
/// When clients need to access it, they simply ask the value holder for its value.
77
/// That is the moment when the value gets loaded (from a database or similar source).
88
/// </summary>
99
/// <typeparam name="T">Value type.</typeparam>
1010
public class ValueHolder<T>
1111
{
1212
private readonly IValueLoader<T> _loader;
13-
private T _value;
13+
private T? _value;
1414

1515
public ValueHolder(IValueLoader<T> loader)
1616
{
@@ -29,4 +29,4 @@ public T Value
2929
return _value;
3030
}
3131
}
32-
}
32+
}

0 commit comments

Comments
 (0)