Read Clean Code

Source: Internet
Author: User

I recently carefully read the Clean Code Clean path when I was busy with public transportation. I once again admire Uncle Bob's humorous essays and his unique views and perspectives. What impressed me most was Uncle Bob's explanation of the data structure and objects.

In general, the data structure refers to the data carrier, exposing the data, and there is almost no meaningful behavior. Should you scream that this is not anemia? Indeed, this is very similar to our anemia. The most common applications are distributed services. They use DTO as an indispensable data transmission object in distributed services such as wcf, webservice, and reset. DTORequest/Response) is a typical data carrier. It only has simple get and set attributes and is more inclined to exist as value objects. Objects, on the contrary, serve as the product of object-oriented systems. They must encapsulate hidden data and expose travel as interfaces, in DDD, domain models tend to operate on themselves or their associated States not only when more data is exposed.

Although there are subtle differences between data structures and objects, they lead to different essential differences: the code using the data structure allows you to add new behavior functions without modifying the current data structure), and the object-oriented Code allows you to add new classes without modifying the existing functions. In other words, it is difficult to add new data types to the data structure. Because all functions need to be modified, it is difficult to add new functions for Object-Oriented code, because all classes need to be modified. In any complex system, data structures and objects exist at the same time. We need to determine whether we need to add new data types or new behavior functions.

The module should not understand the internal situation of the objects it operates on, and hide the objects, A more detailed understanding of the method f of object A should also be able to call only the following objects:

The method should not be used with any object operation returned by calling a method. In other words, the method should be used together with a friend to speak with a stranger. For example, ctxt. getOptions (). getSearchDir (). getAbsolutePath () is the inverse example mode of the dimit rule.

However, the premise of the current dimit rule is the object. If it is a data structure and there is no behavior, they will naturally expose its internal data structure, and the dimit rule will also become invalid.

As the most important feature of object-oriented features, encapsulation and hiding is the most important feature of object-oriented. A good object-oriented code must be a good way to hide and encapsulate the internal details of an object, after encapsulation, there will be polymorphism, delegation, and so on. A good object-oriented code must be well concealed and encapsulated, and easy to test. unstable factors are often concentrated in a small or fixed location, changes due to instability will not spread over larger areas.

Finally, we recommend the next book, which is worth looking at in free time. There is no guarantee that the Code will be written neatly after reading the Code, so that the boy scouts military rule "the Code checked in each time is more neat than the code checked out ", it is not like a beautiful prose. This requires continuous practice discovery in project practice, but it has a guiding role in the meaning of code quality.

I always feel that my technology is still very poor, so I always constrain myself to take the time to read some books, from different perspectives, different fields or ideas to improve and accumulate.

The object-oriented principles include:

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.