Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0711e91

Browse files
Update bridge pattern examples
1 parent 4784c92 commit 0711e91

File tree

23 files changed

+115
-157
lines changed

23 files changed

+115
-157
lines changed

‎src/StructuralPatterns/Adapter/AdapterLibrary/BillingSystemExample/BillingSystemExecutor.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public static void Execute()
2121
// but since it isn't compatible with the 3rd party billing system interface we must use adapter.
2222
// The 3rd party billing system expects List<Employee>, but the current HR system works only with string[,].
2323
// Hide that using adapter design pattern (note that the client is not aware of what's happening under the hood).
24+
// The client code doesn't get coupled to the concrete adapter class as long as it works with the adapter via the interface.
25+
// In this case the client is coupled with the concrete adapter class only because we don't use dependency injection for demo purposes.
2426
ISalaryProcessor salaryProcessor = new HRSystemAdapter();
2527
salaryProcessor.ProcessSalaries(employeesInfo);
2628
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DevicesAndRemotesExample/Abstractions/AdvancedRemoteControl.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public virtual void Mute()
1515
Console.WriteLine("Mute smart TV Command is issued through advanced remote.");
1616
_device.Volume = 0;
1717
}
18-
}
18+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DevicesAndRemotesExample/Abstractions/Common/RemoteControl.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class RemoteControl
1212
protected readonly Device _device;
1313
protected readonly int _volumeChangeStep;
1414

15-
public RemoteControl(Device device)
15+
protected RemoteControl(Device device)
1616
{
1717
_device = device;
1818
_volumeChangeStep = 5;
@@ -72,4 +72,4 @@ public void ChannelDown()
7272

7373
_device.Channel = newChannel;
7474
}
75-
}
75+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DevicesAndRemotesExample/Abstractions/UniversalRemoteControl.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ public UniversalRemoteControl(Device device)
99
: base(device)
1010
{
1111
}
12-
}
12+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DevicesAndRemotesExample/DevicesAndRemotesExecutor.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ public static void Execute()
2121
advancedRemote.Mute();
2222
advancedRemote.TogglePower();
2323
}
24-
}
24+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DevicesAndRemotesExample/Implementations/Common/Device.cs‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class Device
1212
private int _volume;
1313
private int _channel;
1414

15-
public Device()
15+
protected Device()
1616
{
1717
Console.WriteLine("Device turning on process started...");
1818

@@ -24,10 +24,7 @@ public Device()
2424

2525
public int Volume
2626
{
27-
get
28-
{
29-
return _volume;
30-
}
27+
get => _volume;
3128
set
3229
{
3330
_volume = value;
@@ -37,10 +34,7 @@ public int Volume
3734

3835
public int Channel
3936
{
40-
get
41-
{
42-
return _channel;
43-
}
37+
get => _channel;
4438
set
4539
{
4640
_channel = value;
@@ -52,13 +46,9 @@ public int Channel
5246

5347
public bool IsTurnedOn { get; private set; }
5448

55-
public virtual void TurnOn()
56-
{
49+
public virtual void TurnOn() =>
5750
IsTurnedOn = true;
58-
}
5951

60-
public virtual void TurnOff()
61-
{
52+
public virtual void TurnOff() =>
6253
IsTurnedOn = false;
63-
}
64-
}
54+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DevicesAndRemotesExample/Implementations/Radio.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public override void TurnOff()
1515
base.TurnOff();
1616
Console.WriteLine("Radio is turned off.");
1717
}
18-
}
18+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DevicesAndRemotesExample/Implementations/SmartTV.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public override void TurnOff()
1515
base.TurnOff();
1616
Console.WriteLine("Smart TV is turned off.");
1717
}
18-
}
18+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DocumentsAndFormattersExample/Documents/Book.cs‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ public Book(IFormatter formatter)
1010
{
1111
}
1212

13-
public string Title { get; set; }
14-
15-
public string Author { get; set; }
16-
17-
public string Text { get; set; }
13+
public string Title { get; set; } = string.Empty;
14+
public string Author { get; set; } = string.Empty;
15+
public string Text { get; set; } = string.Empty;
1816

1917
public override void Print()
2018
{
21-
Console.WriteLine(formatter.Format("Title", Title));
22-
Console.WriteLine(formatter.Format("Author", Author));
23-
Console.WriteLine(formatter.Format("Text", Text));
19+
Console.WriteLine(_formatter.Format("Title", Title));
20+
Console.WriteLine(_formatter.Format("Author", Author));
21+
Console.WriteLine(_formatter.Format("Text", Text));
2422
Console.WriteLine();
2523
}
26-
}
24+
}

‎src/StructuralPatterns/Bridge/BridgeLibrary/DocumentsAndFormattersExample/Documents/Common/Document.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace BridgeLibrary.DocumentsAndFormattersExample.Documents.Common;
44

55
public abstract class Document
66
{
7-
protected readonly IFormatter formatter;
7+
protected readonly IFormatter _formatter;
88

9-
public Document(IFormatter formatter)
9+
protected Document(IFormatter formatter)
1010
{
11-
this.formatter = formatter;
11+
_formatter = formatter;
1212
}
1313

1414
public abstract void Print();
15-
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /