Facade C #
Appearance factory Mode c # simple example
Function: each player has its own mobile and jumping functions. This function is implemented in the appearance mode. All players are moved in function 1 and all player jumping functions are combined in function 2.
Namespace facade
{
Public partial class Form1: Form
{
Private void btnFacade_Click (object sender, EventArgs e)
{
FacadeFactory ff = new facadeFactory (); // The appearance mode hides players. The user does not know how many players there are.
Ff. move (); // implement the appearance function 1
This. listBox1.Items. Add (ff. movestring );
Ff. jump (); // implement the appearance function 2
This. listBox1.Items. Add (ff. jumpstring );
}
}
Public abstract class play // abstracts all players
{
Public string movestring {get; set ;}
Public string jumpstring {get; set ;}
Public abstract void move ();
Public abstract void jump ();
}
Public class play1: play // Player 1
{
Public override void move ()
{
Movestring = "play1 move ";
}
Public override void jump ()
{
Jumpstring = "play1 jump ";
}
}
Public class play2: play // PLAYER 2
{
Public override void move ()
{
Movestring = "play2 move ";
}
Public override void jump ()
{
Jumpstring = "play2 jump ";
}
}
Public class facadeFactory // factory implementation of appearance Mode
{
Public string movestring;
Public string jumpstring;
List Plays = new List ();
Play playone = new play1 ();
Play playtwo = new play2 ();
Public facadeFactory ()
{
Plays. Add (playone );
Plays. Add (playtwo );
}
Public void move () // appearance mode function 1: two players move together
{
Foreach (play playt in plays)
{
Playt. move ();
Movestring + = playt. movestring;
}
}
Public void jump () // appearance mode function 2: two players team up and jump together
{
Foreach (play playt in plays)
{
Playt. jump ();
Jumpstring + = playt. jumpstring;
}
}
}
}