Design Patterns: Solidify Your C # Application Arch

Source: Internet
Author: User
Design Patterns: Solidify Your C # Application Architecture with Design Patterns Chinese edition (part 1) optimizer)

Keyword design pattern singleton strategy decorator composite state

SOURCE http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/dnmag01/html/PATTERNS. asp

Design Patterns: Solidify Your C # Application Architecture with Design Patterns Chinese edition (part 1)
Author: Samir Bajaj
Translator: Glory
[Translation: C # Advanced article. The translator simply sorts out the C # examples provided by Samir (some of the code provided by the author cannot be compiled in the translator's environment) and compiles the corresponding C ++ example, put them in comments for readers to compare. All C # and C ++ debugging environments are Microsoft Visual Studio. NET 7.0 Beta2]
The following is a complete example of the state mode.
C # example:
Using System;
Abstract class State
{
Public virtual void AddNickel (VendingMachine vm ){}
Public virtual void AddDime (VendingMachine vm ){}
Public virtual void AddQuarter (VendingMachine vm ){}
Protected virtual void ChangeState (VendingMachine vm, State s)
     {
Vm. ChangeState (s );
     }
}
Class VendingMachine
{
Private State state;
Public VendingMachine ()
     {
Console. WriteLine ("The Vending Machine is now online: product costs 25c ");
State = Start. Instance ();
     }
Public void ChangeState (State)
     {
State =;

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.