Reconstruction Method 29: replace record with data class (replace record with data class)

Source: Internet
Author: User

 

You need to deal with the record structure in the traditional programming environment. Creates a "dumb" Data Object for this record.

Motivation: Record structures are the common nature of many programming environments. There are some reasons to bring them into object-orientedProgramMedium: You may face a legacy program, or you may need to use a traditional API to communicate with the record structure, or process records read from the database. In these cases, you need to create an interface class to process the external data. The simplest way is to first create a class that looks like an external record, so that some fields and functions can be moved to this class in the future. An uncommon but notable case is that the elements at each position in the array have a specific meaning. In this case, replace array with object (replacing the array with an object) should be used ).

Practice: 1. Create a class to indicate this record.

2, Corresponding to each item of data in the record, create a corresponding private field in the new class. And provide the corresponding value/set value function.

Now, you have a "dumb" Data Object. This object does not have any useful behavior yet, but further refactoring will solve this problem.

 

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.