Facade C #

Source: Internet
Author: User

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;
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.