Taste programming ~ The underlying developer should design a font class like this

Source: Internet
Author: User

Taste programming is not simply based on the knowledge in books, but summarized in the practical development process. There may be multiple methods for a problem, however, no matter which method you use, remember that you must consider the Code's scalability, readability, and robustness, and check whether the code you write is reasonable. This requires your own efforts, design with your heart. Do not be ambiguous in code design!

In the following example, a Font class is designed, but the two results are completely different.

Example 1:

                            Size { ;                             Unit{;                            Name { ;                             Style { ; 

Example 2: pay more attention to code readability, scalability, and rationality. Although the code length is increased, it is not too long. It is friendly for upper-level developers.

                  = = = = =                                      FontSize(==                            Size { ;                            Unit Unit { ;                                              FontSize Size { ;                             Name { ;                            FontStyle Style { ; 

Provides a method for outputting a font style.

                                             IEnumerable<> ((fontStyle & FontStyle.Bold) ==   ((fontStyle & FontStyle.Italic) ==   ((fontStyle & FontStyle.Strikeout) ==   ((fontStyle & FontStyle.Underline) ==   (fontStyle ==  

OK, perform a test.

           Font font = = =  FontSize(= FontStyle.Bold |=>

Result

In fact, from example 2, we can see a lot of things. It uses classes, structures, enumerations, iterations, and so on. We can see that the FontStyle enumeration is identified by the Flags feature, in this case, it supports bitwise operations. In this example, a method is provided to return the result set of bitwise operations in an iterative manner. This is a bright spot. Through this method, it can be extended to other enumeration types, such as user permission design (view, delete, add, update) and file attribute design (read-only, archive, hidden). For underlying developers, you need to develop the corresponding methods for these types. Such a design is very friendly for surface developers!

 

 

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.