Computer Room fee system cooperation edition (4)-generic solution

Source: Internet
Author: User

Computer Room fee system cooperation edition (4)-generic solution

************Preface:

Start with a question: "What is a wildcard "? Solution: generics are type abstract classes. What is the role: "Through abstraction and encapsulation of types, We can greatly reduce the amount of code ".

From the beginning, the word "abstract" is constantly repeated in the ear. However, before you start a project, especially before you try to use object-oriented thinking to create a project, "abstraction" is always a word in your mind. In a specific project, how do we make the courseware Abstract Step by Step? -- Inheritance, generic ......

************The relationship between "generic" and Abstraction:

  • Figure 1: DAL layer class diagram when no frame is used


    Note:

    ① Same: This layer class graph has a lot of repeated code, and the methods in the class have 90% similarity.

    ② Different: the input and returned objects of each class are different.

    • Figure 2: DAL layer class diagram using OOFramework (as shown in figure 3)


      Note:

      The common methods are abstracted to the RepositZ syntax? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> cipher/aoaPDv7j2vt/cipher + c1_vcd4kpha + yrnTw7TLst/cipher + hozwvcD4KPHA + IDwvcD4KPHVsIHR5cGU9 "disc">

    • Figure 3: Structural Diagram of the DAL Layer



      ************Self-solution:

      At the beginning, I did not understand generics. You cannot understand the meaning of "type abstraction". However, after a project experience, you can now get a general understanding of "generic ". In fact, "generics" play the same role as abstract classes and abstract methods, except that they are used to abstract the things in the brackets behind classes or methods.

      ************Benefits:

      ① Provide services for different objects:With generics, the same code serves different objects.

      ② Improved Abstraction:Without generics, we can only abstract some classes and abstract methods. But with "generics", we can abstract all input parameters and returned values.

      ③ Reduce code duplication:Abstract can reduce a lot of code. "generic" is a small part of abstraction, so "generic" must be learned.

      ④ The Only Way to object orientation:The three elements of object-oriented are based on abstraction, while "generic" is a small part of abstraction. Therefore, "generic" is the only way to go for object-oriented development.

      ⑤ Start of architecture:To do a good job in architecture, object-oriented must be mastered, and "generic" is an important indicator of determining whether or not object-oriented.

      ************Summary:

      I once demonstrated the architecture of the system in "Data room charging system cooperation edition (I) -- framework setup", but Mr. Mi wrote in his comment:"

      In this system, you cannot see that you are using generics !" At that time, I didn't quite understand why the teacher said that I didn't use generics. I did not know why I had forgotten to draw generics in the framework diagram after I returned this summary. Maybe I just forgot it at the time, but now it seems that I did not forget it at the beginning, but I did not understand generics at all. Correct the blog image here:


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.