We also talk about the design mode, instance ticket printing and parsing decorator.

Source: Internet
Author: User

... Preface

During World War II, blue funnel shipping companies needed to transport supplies from the United States to England through the Atlantic Ocean.

Unfortunately, they soon became the main target of the German fleet.

The company's management personnel also promptly realized that the young crew members suffered a large proportion of casualties during the attack.

So they hired a person named "Kurt Hahn" who was very smart and established an organization that still exists-"Outward Bound ".

The Organization established a 28-day course specifically designed to teach young crew members experience-how to combine the knowledge they learned at school to make better use of them at critical moments.

Practice has proved that this course can effectively reduce the casualty rate of young crew members.

... Design patterns in software development

The design pattern, to put it bluntly, is some experience in the software development process.

As if I understood Sun Tzu's Art of War, the war may be easier and more beautiful.

To learn the design model, it is best to have a deep understanding of more than one object-oriented programming language.

Otherwise, learning is not only painful, but also has little effect.

Of course, it may be a good way to learn object-oriented programming languages through design patterns.

(If I become a college teacher one day, I will try this teaching mode. I started dreaming again, haha ...)

... How to learn Design Patterns

The key to learning design patterns is to have good examples.

Some young people buy books; some even read original English books;

Actually, this is not necessary.

Open cnblogs and enter "design mode". There will be many good series of articles. Read them carefully.

People who write these series are experienced and advanced, which is much better than empty preaching in books.

... Application of decorator mode in ticket printing -- throw a problem

The decorator mode can be parsed in all examples.

If you understand object-oriented languages, you can see that aonticketprinter and citiprintticket are two entity classes used to print the subject of tickets for customers "Aon" and "Citi.

Because of their different services, they are designed into two different entity classes.

The customer currently requires that the ticket subject is mandatory, but the operator can selectively add information to the ticket header and tail when printing the ticket.

The UI may be as follows:

 

New users, inexperienced people, people who do not understand design patterns, including myself ....

Using the object-oriented design idea, the underlying class design may be as follows:

 

This design isTerror is correct and effective.

Some people may say, why do we need to generate so many inheritance classes without logical judgment?

The basic principles of object-oriented design are as follows:For extended development, the modification is closed.

 ... Decorator mode application in ticket printing -- solve the problem (with code attached)

Analysis shows that the printer method of the inherited class calls Base. Print () at any time (),Some features are added only on the basis of the parent class method.

If this is the case, decorator can be used.

This design isMagic is correct and effective.

Even if we add 10000 new customers in the future, what we need to do is also interesting. After all, the business of different customers is always a little different.

 

Design patter-decorator example

Design patter vs2010-decorator example 

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.