The bridge mode is relatively simple, mainly using a combination.
UML diagram:
In this article, I have created some scenarios, which are not often used in Dota.
Dota has five teammates. If I say that, if your teammates eat too much watermelon and want to take a nap, but now is the key. He is a group controller, you can't sacrifice a pair of underpants for victory. We can only share units. Now you can control yourself or the heroes of your teammates. You can click a hero to control it. Here you can use bridging.
As mentioned above, bridging is a combination. First, heroes are indispensable unless they have been sent back to spring water and are not reborn:
Public Interface Ihero
{
Void Action ();
}
/// <Summary>
/// Soul guard
/// </Summary>
Public Class Terrorblade: ihero
{
Public Terrorblade ()
{
}
# RegionIhero Member
Public VoidAction ()
{
Landpyform. Form. outputresult ("Terrorblade action");
}
# Endregion
}
/// <Summary>
/// Druid
/// </Summary>
Public Class Syllabear: ihero
{
Public Syllabear ()
{
}
# RegionIhero Member
Public VoidAction ()
{
Landpyform. Form. outputresult ("Syllabear action");
}
# Endregion
}
What's worse? Of course it's our players. is a game called a game without any players?
Public Class Gamer
{
Private Ihero _ hero;
Public Ihero hero
{
Set {_ Hero = Value ;}
}
Public Void Action ()
{
_ Hero. Action ();
}
}
The gamer class contains the ihero interface, which is dependent on Inversion. No matter what new hero Code You don't need to change it. The decoupling is absolutely decoupled. Headfirst says, "use multiple combinations and use less inheritance.
The test code is as follows:
Dotapatternlibrary. Bridge. gamer = new dotapatternlibrary. Bridge. gamer ();
Dotapatternlibrary. Bridge. ihero hero = new dotapatternlibrary. Bridge. syllabear ();
Gamer. Hero = hero;
Gamer. Action ();
Hero = new dotapatternlibrary. Bridge. terrorblade ();
Gamer. Hero = hero;
Gamer. Action ();
You can switch between controllable heroes at any time.
Complete code: Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
UsingDotacommon;
NamespaceDotapatternlibrary. Bridge
{
Public InterfaceIhero
{
VoidAction ();
}
/// <Summary>
/// Soul guard
/// </Summary>
Public Class Terrorblade: ihero
{
Public Terrorblade ()
{
}
# RegionIhero Member
Public VoidAction ()
{
Landpyform. Form. outputresult ("Terrorblade action");
}
# Endregion
}
/// <Summary>
/// Druid
/// </Summary>
Public Class Syllabear: ihero
{
Public Syllabear ()
{
}
# RegionIhero Member
Public VoidAction ()
{
Landpyform. Form. outputresult ("Syllabear action");
}
# endregion
}
Public class gamer
{< br> private ihero _ hero;
Public ihero hero
{< br> set {_ hero = value ;}< BR >}
Public void action ()
{< br> _ hero. action ();
}< BR >}< br>