Use the design mode to solidify your C # Program (6-1)

Source: Internet
Author: User

Use the design mode to solidify your C # Program (6-1)

Design Patterns: Solidify Your C # Application Architecture with Design Patterns Chinese edition (Part 2)
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]

C ++ example: [Note: Because the code in this example is relatively complex, the class declaration and definition are separated from J]

State. h
# Include "stdafx. h ";
Class State;
Class VendingMachine;
Class Start;
Class Five;
Class Ten;
Class internal tee;
Class Twenty;
Class State
{
Public:
Virtual void AddNickel (VendingMachine * vm ){}
Virtual void AddDime (VendingMachine * vm ){}
Virtual void AddQuarter (VendingMachine * vm ){}
Protected:
Virtual void ChangeState (VendingMachine * vm, State * s );
};
Class VendingMachine
{
Private:
State * state;

......

Delete Start: Instance ();//@
Delete Five: Instance ();//@
Delete Ten: Instance ();//@
Delete deleteen: Instance ();//@
Return 0;
}
/* The following is the output result of a running task:
The Vending Machine is now online: product costs 25c
Credit: 0c
Insert a coin <5, 10, 25>: 5
Credit: 5c
Insert a coin <5, 10, 25>: 10
Credit: 15c
Insert a coin <5, 10, 25>: 5
Credit: 20c
Insert a coin <5, 10, 25>: 5
Dispensing product... Thank you!
*/
]

Conclusion

The design model draws on the essence of years of experience in solutions to common problems in object-oriented software design. Regardless of the scale of the project, they provide answers to the problems most software developers encounter. C # increases the productivity of programmers, adds features that can promote object-oriented design, and reduces the manual labor burden of developers. The combination of the two is always unfavorable.

Related Article

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.