Some suggestions about naming specifications

zhaozj2021-02-08  445

Class name Kent Beck proposes most of the rules. Kent Beck's "SmallTalk Best Practice Pattern" is all books I have read so far, the most inquiry of my aesthetic views - profound knowledge and brushworks of spring and autumn.

Simple superclass name - the naming of design purposes is always subject to various factors. You want to make the name as short as possible, easy to enter, format, and easy to say. At the same time, you also want the name to contain more information as much as possible so that the reader can understand the actual content included in the name faster. You may take some names that are familiar with people so that you can pass more common experiences in your name. At the same time, you also want the name as soon as possible, others' code naming will not be repeated with you. The first rule given by Kent Beck is not abbreviated. Abbreviations are considered for the considering of the enumeration (10-100 times within 20 years) (10-10000 times in 20 years). It takes two steps to understand the narration. The first step is to understand the words of these abbreviations, and the second step takes the meaning representative of these words. Named a large-level root class is a major decision. In the next 20 years, people may constantly use the name you give. You have to do not make mistakes. People usually add a variety of modifications when naming super categories, computer scientific significance, giving people a deep impression, but eventually, meaningless words, such as Object, Thing, Component, Part, Manager, Entity or Item. You are creating a vocabulary instead of writing a program. Temporarily do a poet. Simple, energetic, easy memory is far more effective than saying all content. Rules: Name A Superclass with a single word what conveys ITS Purpose in the design. (Name superclams with a word, convey its design purposes), good examples include: Number, Collection, Magnitude, Model

A full range of sub-names - one way to distinguish between different nomenclas is to give a unique name. The only name allows you to use the shortest information to express the most information. This is correct for general terms. Array is a subclass of Collection because most people know what "Array" means. However, in most cases, the hierarchy of the inheritance is important for understanding your code, especially a subclass concept is superclatrifugated, and the situation is achieved at the same time. You need to pass two parts: 1. How the new class is the same, and 2. How different new classes are different to express the same, you can borrow superclass names. This is not necessarily a direct subclass and parental relationship, and there is a distance in the level. To express the expression, you need a word to emphasize why the new category is not a reasonable reason. So, there is rule: name subclasses in your hierarchies by prepending on an adjective to the superclassname. (Adding a subclass in your hierarchy before the superclass name.) An example: Biginteger is an integer that can express a lot of large numbers.

Method Naming - Unveiling why good code has a lot of simple methods, code may only have one line, such as: Class Paragrapheditor. . . . Public void highlight (all) {reverse (all);} This highlight is just assigned to Reverse, why still needs? The key is Communication. Because there is this method, you can use highlight to speak with highlight. I want to brighten a zone, I will highlight it. Of course you can use Reverse directly, the result is the same. But all calling code revealed the implementation - "I highlight it by reversing a rectangle." The code should be disclosed, and it is more convenient to be repaired more convenient. If you want a paragrapheditor to brighten with the color, just inherit Paragrapheditor and override you. So: Communicate What Is To Be Done Rather Than How It Is To Be Done. Communicate what you want (interface) instead of you do (implement). Example (temporary) Variable Named - Implied Role Any instance variable conveyed information includes two parts: 1. What is its purpose? 2. How do it been used? The purpose of a variable or that it is very important to the reader because it can correctly guide the reader's attention. Generally, you have a purpose in your head when you read the code. If you understand the role of the variable, this role is not related to your purpose, then you can directly skip the independent code of using the variable. If the role of this variable is found to be related to your purpose, then you will immediately reduce your reading range - those related codes that reference this variable. How to use and send it to what message is usually its "type". The type of understanding is not important. However, for instance variables, you can understand that the role of this variable is its name. If there is two instance variables in a point called int1, int2 is not x, y, then which one is a horizontal coordinate, which one is before, you may have to have a bunch of code. What's more, you have to read a lot of code related to it. The type of variable is easy to declare from it, and the news passed to it. So: Name Instance Variable for the Role The Play In The Computation. Make the name pluralif the variable will hold a collection. (Name the role assumed by the example variable in the calculation. If the variable holds a collection, use the plural.)

转载请注明原文地址:https://www.9cbs.com/read-513.html

New Post(0)