Design pattern general Beginner, intermediate, senior programmers like to hang on the words. I guess we all have a lot of books about design patterns around here. Design pattern is the solution set accumulated by the programmer's old-timers according to their project experience. Therefore, there is no need to take the design model as a hard thing, other people's experience can be used to understand the design ideas, why this scenario to use this model. Perhaps the older generation of programmers is indeed much better than the current programmer, after all, it is difficult to find their own online design model.
The worm is a first.
A brief introduction to 2 patterns that are often used in my project
1. Robot Plug-in Mode
What the so-called robot plug-in, you can understand this. You have a robot, but it's not certain what you need this robot to do. Inserting different cards allows the robot to behave differently. Like AOP, AOP is a system-level perspective, and the plug-in pattern is based on behavior.
Look at the code directly
Define behavior:
public static event eventhandler<robotcanceleventargs> Deleteingrobot; protected virtual void Ondeleteingrobot (Robotcanceleventargs e) {Eventhandler<robotcanceleventargs
> tmp = Deleteingrobot;
if (TMP!= NULL) TMP (this, e);
public static event eventhandler<robotcanceleventargs> Bhingrobot; <summary>///robot action before triggering event///</summary> protected virtual void Onbhingrobot (ROBOTC
Anceleventargs e) {eventhandler<robotcanceleventargs> tmp = Bhingrobot;
if (TMP!= NULL) TMP (this, e);
public static event eventhandler<eventargs> Bhedrobot; <summary>///robot action triggers///</summary> protected virtual void Onbhedrobot (EventArgs
e) {eventhandler<eventargs> tmp = Bhedrobot; if (tmp!= nuLL) TMP (this, e);
public static event eventhandler<servingeventargs> Servingrobot; <summary>///triggers///</summary> protected virtual void onserving when calling robot behavior (Servingev
Entargs e) {eventhandler<servingeventargs> tmp = Servingrobot;
if (TMP!= NULL) TMP (this, e); }
Behavior Examples:
public bool Bhrobot (out string message)
{message
= string. Empty;
Robotcanceleventargs e = new Robotcanceleventargs ();
Onserving (e);
if (!e.cancel)
{
var v = robotservice.bhrobot (this);
if (v)
{
Onbhedrobot (eventargs.empty);
return true;
}
return false;
}
else
{message
= E.message;
return false;
}
}
Registration card:
[Extension ("", "1.0", "late-night Bugs")]
public class Cardrobot
{
static Cardrobot ()
{
Robot.servingrobot + = new eventhandler< Servingeventargs> (comment_servingdelegate);
}
static void Comment_servingdelegate (object sender, Servingeventargs e)
{
try
{
//do something
}
catch (Exception ex)
{
//log4n.warnlog ("Badwordfilterextension Exception:", ex);
}
}