File tree Expand file tree Collapse file tree 10 files changed +25
-53
lines changed
src/BehavioralPatterns/TemplateMethod/TemplateMethodLibrary Expand file tree Collapse file tree 10 files changed +25
-53
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,6 @@ public void Make()
16
16
17
17
protected abstract void Bake ( ) ;
18
18
19
- protected virtual void Slice ( )
20
- {
19
+ protected virtual void Slice ( ) =>
21
20
Console . WriteLine ( $ "Slicing the { GetType ( ) . Name } !") ;
22
- }
23
- }
21
+ }
Original file line number Diff line number Diff line change @@ -16,4 +16,4 @@ public static void Execute()
16
16
var wholeWheatBread = new WholeWheatBread ( ) ;
17
17
wholeWheatBread . Make ( ) ;
18
18
}
19
- }
19
+ }
Original file line number Diff line number Diff line change 2
2
3
3
public class WhiteBread : Bread
4
4
{
5
- protected override void MixIngredients ( )
6
- {
5
+ protected override void MixIngredients ( ) =>
7
6
Console . WriteLine ( "Gathering ingredients for white bread." ) ;
8
- }
9
7
10
- protected override void Bake ( )
11
- {
8
+ protected override void Bake ( ) =>
12
9
Console . WriteLine ( "Baking the white bread for 15 minutes." ) ;
13
- }
14
- }
10
+ }
Original file line number Diff line number Diff line change 2
2
3
3
public class WholeWheatBread : Bread
4
4
{
5
- protected override void MixIngredients ( )
6
- {
5
+ protected override void MixIngredients ( ) =>
7
6
Console . WriteLine ( "Gathering ingredients for whole wheat bread." ) ;
8
- }
9
7
10
- protected override void Bake ( )
11
- {
8
+ protected override void Bake ( ) =>
12
9
Console . WriteLine ( "Baking the whole wheat bread for 20 minutes." ) ;
13
- }
14
- }
10
+ }
Original file line number Diff line number Diff line change @@ -25,20 +25,14 @@ public void TemplateMethod()
25
25
/// <summary>
26
26
/// These operations already have implementations.
27
27
/// </summary>
28
- protected virtual void BaseOperation1 ( )
29
- {
28
+ protected virtual void BaseOperation1 ( ) =>
30
29
Console . WriteLine ( "AbstractClass says: I am doing the bulk of the work" ) ;
31
- }
32
30
33
- protected virtual void BaseOperation2 ( )
34
- {
31
+ protected virtual void BaseOperation2 ( ) =>
35
32
Console . WriteLine ( "AbstractClass says: But I let subclasses override some operations" ) ;
36
- }
37
33
38
- protected virtual void BaseOperation3 ( )
39
- {
34
+ protected virtual void BaseOperation3 ( ) =>
40
35
Console . WriteLine ( "AbstractClass says: But I am doing the bulk of the work anyway" ) ;
41
- }
42
36
43
37
/// <summary>
44
38
/// These operations have to be implemented in subclasses.
@@ -59,4 +53,4 @@ protected virtual void Hook1()
59
53
protected virtual void Hook2 ( )
60
54
{
61
55
}
62
- }
56
+ }
Original file line number Diff line number Diff line change @@ -8,10 +8,8 @@ public class Client
8
8
/// as long as it works with objects through the interface of their base class.
9
9
/// </summary>
10
10
/// <param name="abstractClass">Abstract class.</param>
11
- public static void ProcessSomething ( AbstractClass abstractClass )
12
- {
11
+ public static void ProcessSomething ( AbstractClass abstractClass ) =>
13
12
// Initial operations
14
13
abstractClass . TemplateMethod ( ) ;
15
- // Additional operations
16
- }
17
- }
14
+ // Additional operations
15
+ }
Original file line number Diff line number Diff line change @@ -14,4 +14,4 @@ public static void Execute()
14
14
Console . WriteLine ( "\n Working with concrete class 2..." ) ;
15
15
Client . ProcessSomething ( new ConcreteClass2 ( ) ) ;
16
16
}
17
- }
17
+ }
Original file line number Diff line number Diff line change 6
6
/// </summary>
7
7
public class ConcreteClass1 : AbstractClass
8
8
{
9
- protected override void RequiredOperations1 ( )
10
- {
9
+ protected override void RequiredOperations1 ( ) =>
11
10
Console . WriteLine ( "ConcreteClass1 says: Implemented Operation1" ) ;
12
- }
13
11
14
- protected override void RequiredOperation2 ( )
15
- {
12
+ protected override void RequiredOperation2 ( ) =>
16
13
Console . WriteLine ( "ConcreteClass1 says: Implemented Operation2" ) ;
17
- }
18
- }
14
+ }
Original file line number Diff line number Diff line change 5
5
/// </summary>
6
6
public class ConcreteClass2 : AbstractClass
7
7
{
8
- protected override void RequiredOperations1 ( )
9
- {
8
+ protected override void RequiredOperations1 ( ) =>
10
9
Console . WriteLine ( "ConcreteClass2 says: Implemented Operation1" ) ;
11
- }
12
10
13
- protected override void RequiredOperation2 ( )
14
- {
11
+ protected override void RequiredOperation2 ( ) =>
15
12
Console . WriteLine ( "ConcreteClass2 says: Implemented Operation2" ) ;
16
- }
17
13
18
- protected override void Hook1 ( )
19
- {
14
+ protected override void Hook1 ( ) =>
20
15
Console . WriteLine ( "ConcreteClass2 says: Overridden Hook1" ) ;
21
- }
22
- }
16
+ }
Original file line number Diff line number Diff line change @@ -13,4 +13,4 @@ public override void Execute()
13
13
BreadExecutor . Execute ( ) ;
14
14
ConceptualExecutor . Execute ( ) ;
15
15
}
16
- }
16
+ }
You can’t perform that action at this time.
0 commit comments