C # design mode

Source: Internet
Author: User

Design Mode: simplified architecture

I. Pipeline Creation

1. Ticket Mode

Note: There is a kind that determines which kind of sub-class to be practically instantiated in the single-sheet bearing structure.

2. Work order method mode

Description: there are common abstract types. A worker produces a pair. The relationship is one-to-one.

3. Abstract worker Mode

Description: two abstracts: one is the industrial abstraction and the other is the product abstraction. Generate a series of products through work orders.

4. Singleton Mode

Note: There is only one global problem. There is only one example.

5. Generator Mode

Description: a hacker, Director, is also a worker to determine which generator to use. Each generator obtains the same data records, and the internal data rows are different.

Operations (product organization components), the most structured form of a product, or different representations.

6. prototype mode

Note: You can use the prototype mode when you need to create a large number of types, or a large pair of images, or when the types need to be modified after creation. It is equivalent to cloning an object.

II. Architecture

Description: a larger type and structure are generated through a combination of types.

1. zookeeper Mode

Description: Yes.ProgramIs another interface.

1.1 category Scheduler

Description: accept the class and assume a new interface.

1.2 million matching images

Description: Object combination. Put the classes to be written into the internal part of the website, and upload new interfaces.

2. Accept connection mode

Description: The same data volume has different display methods. The use of the client terminal is fixed.

A batch interface is called baridge, which indicates the baridgelist and baridge. In this case, it contains a batch interface.

A graphical interface (vislist) is used to display the productlist of an interface.

Usage: baridge B = new baridgelist (check the productlist OF THE vislist Interface );

B. Interface, fill in the data records.

3. Combination Mode

Description: it can represent an integral part of the summary structure or a simplified representation of the data structure. In fact, it is the combination of the object, which has the same

. Such as the organization structure.

4. zookeeper mode:

Description: in fact, it refers to the expansion of a kind of actual instance without the need to create a new object. You can develop an object that contains a common interface. No need

The original class is modified.

For example, for people, you can have students and instructors..., we can introduce them to people. Then, students have the same functions.

The following is an example of the generation:

View code

    Public    Abstract   Class Person {  Public   String Name { Set ; Get  ;}  Public   Int Age { Set ; Get  ;}}  Public   Class  Studentperson: person {  Public  Void  Dowork () {console. writeline (  "  I am studying  "  );}}  Public   Class  Tearch: person {  Public   Void  Dowork () {console. writeline (  "  I'm teaching student  "  );}} ///   <Summary>      ///  Zookeeper Interface  ///   </Summary>     Public   Interface  Idecorator {  Void  Sleep ();}  ///   <Summary>      ///  Verify now  ///  </Summary>     Public   Class  Sleepdecorator: idecorator {person P;  Public  Sleepdecorator (person p ){  This . P = P ;}  # Region Idecorator members Public   Void  Sleep () {console. writeline (  "  {0} sleeping "  , P. Name );}  # Endregion  } 

Token Generation:

Person P = new studentperson () {age = 12, name = "GSW "};
Idecorator decorator = new sleepdecorator (P );
Decorator. Sleep ();

5. External partition mode facade:

Description: The Sub-system is just an operator, and the packet is written into a uniform interface. For example, ODBC is an out-of-the-box mode. Various data vendor vendors are

Different. However, through ODBC, it provides a uniform interface.

6. flyweight mode:

Note: Avoid very similar class opening. Small granularity. Most of the data records are the same, and each item has different memory numbers. Different memory types are stored externally, which can greatly reduce the number of different instances.

7. Proxy mode:

Description: creates a complex object or an object with a large amount of time to form a simple object.

The proxy and the actual response correspond to the same interface.

3. Behavior mode

1. Too many requests

Description: Please wait between classes until you find a class that can be handled. For example, Zookeeper helps the system.

Similar to an else sentence like if elseif Else.

Bearing Type:

View code

    Public   Abstract    Class  Charn {  Protected  Charn Chan;  Public   Void  Addcharn (charn Chan ){  This . Chan = Chan ;} Public  Charn (){}  Public   Abstract   Void Sendtocharn ( String  Message );}  Public   Class  Acharn: charn {  Public   Override   Void Sendtocharn ( String  Message ){ If (Message. indexof ( "  A  " )> = 0  ) {Console. writeline (  "  Contains Letter  "  );}  If (Chan! = Null  ) {Chan. sendtocharn (Message );}}}  Public  Class  Bcharn: charn {  Public   Override   Void Sendtocharn ( String  Message ){  If (Message. indexof ( "  B  " )> = 0  ) {Console. writeline (  "  Contains Letter B "  );}  If (Chan! = Null  ) {Chan. sendtocharn (Message );}}}  Public   Class  Othercharn: charn {  Public   Override   Void Sendtocharn ( String  Message ){  If (Message. indexof ( "  B  " ) < 0 & Message. indexof ( "  A  " ) < 0  ) {Console. writeline (  "  It does not contain letters A and B.  "  );}  If (Chan! =Null  ) {Chan. sendtocharn (Message );}}} 

Jobs:

View code

PublicClassFactorycharn {Public StaticCharn getacharn () {charn Cha=NewAcharn (); charn CHB=NewBcharn (); charn chother=NewOthercharn (); cha. addcharn (CHB); CHB. addcharn (chother );ReturnCha ;}}

For zookeeper:

Static void main (string [] ARGs)
{
Charn CHA = factorycharn. getacharn ();

Cha. sendtocharn ("bhen Hao ");
Console. Readline ();
}

2. Command mode

Description: The sum and lead operations are completely separated.

Used

View code

      Public   Abstract   Class  Command {  Public Command (receiver ){  This . Cycler = Aggreger ;}  Protected  Receiver receiver;  Public   Int Long { Set ; Get  ;}  Public    Abstract    Void  Execute (); Public   Abstract    Void  Undo ();}  Public   Class  Using command: Command {  Public Aggregcommand (aggreger ): Base  (Cycler ){}  Public   Override   Void  Execute () {worker er. dowalk (long );} Public   Override   Void  Undo () {worker er. dowalk ( - Long );}}  Public   Class  Explorer {  Public   Void Dowalk ( Int  Restore length) {console. writeline (  "  Step {0}  " , Required length );}} 

Middle class

View code

  Public     Class  Client {  Private List <command> lst = New List <command> ();  Public    Void  Addcommand (command ){  This  . Lst. Add (command );} Public   Void  Execute (){  If (Lst. Count> 0  ){  Foreach ( VaR Item In  LST) {item. Execute ();}}}  Public   Void  Undo (){  If (Lst. Count> 0  ) {Command = Lst [lst. Count- 1  ]; Command. Undo (); lst. Remove (command );}}} 

Guest terminal license

  static   void  main ( string   [] ARGs) {http://www.cnblogs.com/Teco/admin/EditPosts.aspx? Postid = 2540892 & update = 1hi receiver  =  New   Cycler (); client clent  =  New   client (); clent. addcommand (  New  extends command (extends ER) {long =  12  }); clent. addcommand (  New  extends command (extends ER) {long =  13  }); clent. execute (); clent. undo (); console. readline () ;} 

3. interpreter Mode

Description: analyzes USER commands and an algebra string.

4. iterator Mode

Note: Use a standard interface to access a data column or set in sequence without knowing the implementation details. The iterator in C # requires the basic ienumerator interface.

5. intermediary Mode

Note: It is a class. This class is the only class that knows the details of methods in other classes. It notifies the intermediary when the class changes, the intermediary then transmits these changes to other classes to be notified.

The interaction between processing classes.

6. Memorandum Mode

Note: Save the object status for future recovery.

7. Observer Mode

Note: When the status of the topic object changes, all observer objects are notified so that they can automatically update themselves.

8. Status Mode

Description: allows an object to change its behavior when its internal state changes. The object seems to have modified its class. The States abstract class has several states to inherit the class of this class.

A Status control class statemange. The States class contains the statemange attribute. The statemange class contains the States attribute. Changes the status in the inherited States class. Statemange can be used to read the status of States.

9. Policy Mode

Note: The policy mode is correct.AlgorithmIs to split the responsibility for using the algorithm and the algorithm itself, and delegate to different object management. Rule mode typically packs a series of algorithms into a series of policy classes and serves as a subclass of an abstract policy class. In one sentence, it is: "prepare a set of algorithms and encapsulate each algorithm so that they can be exchanged. "

10. template method mode

Note: Prepare an abstract class to implement part of the logic in the form of a specific method and a specific constructor, and then declare some abstract methods to force the subclass to implement the remaining logic. Different sub-classes can implement these abstract methods in different ways to implement the rest logic differently. Abstract method, virtual method.

11. Visitor Mode

Note: The methods that should have been in another class are used in this class. Class extension.

Structure:

Definition: employee class. One of the methods is required. All classes to be extended must have this method:

Public Virtual void accept (visitor v ){
V. Visit (this );
}

Define the abstract visitor class. The visit method is provided.

Define vacationvisitor to inherit the visitor and process the added method in this class. Gettotaldays

Client call:

Vacationvisitor VAc = new vacationvisitor ();

Employee Employee = new employee ("Susan bear", 55000, 12, 1 );

Employee. Accept (VAC );

VAC. gettotaldays.

 

 

 

 

 

 

 

 

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.