// Introduce the rule mode to separate work
// Apply dependency injection to allow the "execution" to be completed by the injected instance.
// In this way, the new work is completed independently, where to use and where to modify
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace ConsoleApplication1.EighthTest
{
Class EighthTest
{
Public void DoTest ()
{
Employee Wei = new employee ();
Wei. Work = new operations World of Warcraft ();
Wei. Execute the work ();
Console. ReadLine ();
Wei. Work = new handling industry competition ();
Wei. Execute the work ();
}
}
Class employees
{
Public work policy work;
Public void ()
{
Console. WriteLine (work. Execute ());
}
}
Interface Working Policy
{
String execution ();
}
Class operation World of Warcraft: Work Strategy
{
String leleapplication1.eighthtest. Work policy. Execute ()
{
StringBuilder work content = new StringBuilder ();
Work content. AppendLine ("arrange device procurement ");
Work content. AppendLine ("Recruitment customer service, induction training ");
Work content. AppendLine ("advertising ");
Work content. AppendLine ("game market ");
Work content. AppendLine ("launch activity ");
Work content. AppendLine ("............ ");
Return work content. ToString ();
}
}
Class processing industry competition: Work Strategy
{
String leleapplication1.eighthtest. Work policy. Execute ()
{
StringBuilder work content = new StringBuilder ();
Work content. AppendLine ("investigating competitors ");
Work content. AppendLine ("fight ");
Return work content. ToString ();
}
}
// This design seems very clever, but one thing that happened once caused me to dislike derivative things for years.
// Go to the site at a time to maintain projects developed by others. If an error occurs in the program, you need to modify it.
// The trigger error is very simple. Click a button to report an error. I will find it from the Click event of this button.
// In this example, right-click "Wei. Work" in the test code and select to go to the definition. The actual execution is not redirected.
// The program can hardly be maintained by others. A simple form is accompanied by several. cs and an operation for adding records to the table,
// You cannot find the Insert into statement.
// Therefore, if the derived technology is used, you must write the design instructions.
// Otherwise, I would rather see a long if... else, which at least gives me the chance to find the place to execute.
// The Problem of Difficult Derivative maintenance has always plagued me. If not, do not derive.
// There is no delegate here, but another technology-interface is derived. Some people call this application a policy, and others call it a service.
}