Monday, May 4, 2015

Moscow time is displayed in the lobby of Zhong Zhongwen entry


"What is software?" A winter of the last century the early 1990s, at a university in the southeast suburbs of Beijing where a nearly sixties teacher, gave us these computer science student speaking software engineering class that door, asked This problem. For almost that time much chance for me to touch the computer, trash the software is an order in the school room on those puzzling the DEC minicomputer, and 286 PC in those fun racing game Pacman and no. "Software is not just procedures, including document describes the program. Software is the program plus the documentation." The teacher definition of the software, deeply engraved in my mind, its degree of depth, after a long period of time , always makes me feel the influence of the documentation for the software, the program seems to be overshadowed. trash
This practice after graduating from college in my twenty years of software development-related work, and continue to be confirmed. A variety of documents trash - requirements document outline design documents, detailed trash design trash documents, test documents, etc., in a number of software development projects I have experienced, always occupy an important position. "After all, as long as the documents, not afraid to develop trash frequent movement of people." A software development manager told me. In addition to write Word or Excel documents, programmers were also asked to write as much as possible detailed comments in the source code. In the eyes of software development trash manager, writing documents and written comments habits is an important criterion to measure trash whether a competent programmer.
Over the past decade, trash whether it is to develop new features or fixes bug, I've been trying to write the document, write and modify the code and the Notes, and then to test personnel trash to test, test personnel to go to change the proposed bug, it all looks like a textbook to perfect and correct as described. But I finally found, in this way the intrinsic quality of the software developed, such as understandability, testability, scalability, but it does not seem to me with the increase of these efforts is enhanced, trash sometimes it will weaken In other words, this method does not stop bad breeding trash code. Let's start with the traditional waterfall development method, trash a coding practice moves, take a look at what's the problem? That moves moves coding 1.1 Coding Code Kata in English translation, is "Pragmatic trash Programmer: from workers to experts" (ThePragmatic Programmer: From Journeyman to Master) a coauthor, American programmer trash Dave Thomas about 2003 before and after the creation of the word, represents a coding exercise, the programmer can repeatedly trash practice the exercises to improve their programming skills. Kata is a Japanese katakana ka ta into English, the corresponding characters are "type" or "shape", said the conduct for single or double drilled, carefully choreographed operation mode. [1]
Coding moves, saying that white is actually choose that the programmer practice programming problem. Speaking of practice, I can be very natural to think opera singers practice stretching and kicking, comedian practice tongue twisters and open sound, and martial arts Zhan Zhuang people alone and with others learn blows. In contrast, practicing programmers trash seem not so particular about. trash Since the 1980s, the emergence of object-oriented programming language which has more than 30 years, the vast majority of domestic programmers called "exercises", trash merely reading technical books and blog, at most, according to the sample code and then write Some programs, run a little. Even at very high levels of foreign programmers programming until May 2004, the French programmer Laurent Bossavit only wrote about the number of programmers with some coding practice moves "code Dojo" blog. Here the "Coding Dojo" trash English coding dojo in translation, which dojo also from the Japanese, is Katakana-do-u-ji January u into English, the corresponding Chinese character is "temple", referring to a formal trash training in place to provide learning Japanese martial arts students perform exercises together. Due to the small "temple" in the domestic use of the term, and in the "coding dojo" is mainly trash carried out practice activities, the book of the "coding dojo" as "coding practice" below, both the same meaning. Many programmers coding practice means together with two pair of form, procedure coding practice the moves. Coding and coding practice moves in foreign countries has developed nearly 10 years, its influence continues to expand, to 2009 and the emergence of coding retreat (code retreat) a new form, that dozens of programmers together with a full The days to bear on the practice of coding moves in coding practice. Moves coding, coding and coding practice trash retreat in recent years in the country are starting to get some development, such as when writing this book, I've had, "Reconstruction trash and mode" (Refactoring to Patterns), author Joshua Kerievsky in 1995 in the United States trash founder of design patterns inspired by New York study group, in April 2013 in Beijing founded the free public good "Beijing design pattern learning group [2]" to the time of this writing, has organized 10 events, each able to attract 8 ~ 20 programmers to pair practice coding skills. All this seems to indicate that programming is no longer just in accordance with established software architecture or framework to like barrier brick as a passive "fill" code, but like to sing opera, Laughed, practicing martial arts, as more emphasis on human Creativity trash is a need to drill to enlightenment apprenticeship craft.
Let's say in a hotel lobby, there are five clocks show Beijing, London, Moscow, Sydney and New York time. Among them, the London and UTC (CoordinatedUniversal Time, Coordinated Universal Time) time [3] consistent, Beijing 8 hours earlier than UTC time, Moscow four hours earlier than UTC time, Sydney 10 hours earlier than UTC, UTC time is later than New York 5 h. No, you need to adjust the time, just a city alignment if the time clock to go to the city, the time remaining four cities can be correspondingly trash adjusted automatically accurate.
"Identify areas category. Find some important terms from the above list of requirements that, the field can be used as an initial class." You said.
Moscow time is displayed in the lobby of Zhong Zhongwen entry


"In the refinement after class diagram, TimeSubject class can use a named cityClocks of HashMap to hold CityClock class of objects of all five cities. trash In order to facilitate adding or removing objects from which to HashMap city, you need to have attach () and detach () These two methods .TimeSubject class notify () method to do the figure by a note in the box marked trash out, and that for this HashMap cityClocks TimeSubject class member variable, using a for loop to call each of which holds a CityClock object updateCityTime () method to the time all cities will be automatically updated. And the notify () method, you can UtcTime the setUtcTime () method to trigger a call. "
"CityClock class has a private member variable cityTime, to save the local time for each city; it also has a member variable utcTime, used to hold a reference to UtcTime class to facilitate removal from UtcTime in UTC time, to calculate their local time cityTime represented the city. It's every subclass, there is a UTC_OFFSET private static member variables to save each city the difference between UTC time relative to the five sub-class inherits the updateCityTime () method TimeSubject class by the notify () method to call, have already said, and that five sub-class inherits another method setUtcTime (), is used to call UtcTime class setUtcTime () method, and thus be able to trigger a call TimeSubject notify class () method, enabling the city to update a time, you will be able to automatically trash update the time for all cities. "
cityClocks.put (cityName, cityClock);

"Uh, utcTime name really makes me a little tangled, it has two meanings, both UtcTime refer to an object of this class, you can refer to UtcTime this class to save the member variables UTC time. In order to distinguish, I took the latter changed his name utcZeroTime, represents the difference between UTC time and the time is zero, so CityClock class abstract method setUtcTime () was renamed to become setUtcZeroTime (), it and the abstract methods updateCityTime () input parameters renamed utcZeroTime up. "you said.
cityClock.updateCityTime (utcZeroTime);
"Then, one by one, the five cities realize that the clock class. Start BeijingClock start." You say.
"BeijingClock class implements the parent class abstract updateCityTime () method to the UTC time plus UTC_OFFSET difference between Beijing and the UTC time, you can get GMT. Originally, I wanted to continue to achieve a parent class in the class in BeijingClock abstract setUtcZeroTime () method, but I find this method can achieve into the parent class, which can make it a 5 subcategories reuse. So I changed a bit parent trash CityClock, the abstract setUtcZeroTime () method change as a method has been implemented. "You said.
Here is a main () method of the Main class code includes:
System.out.println ("The trash time of Moscow is" + TimeSubject.getCityClock ("Moscow") getCityTime ().);
"The main () method has three steps to be done. The first step, use TimeSubject class attach () method, the target five cities are added to the class HashMap that static member variables in Step 2, The Beijing time to adjust the clock to 9:00, step 3, this time five cities trash are printed out, see the results. Step 1 no problem, but Step 2 and Step 3 to use two Interface, has written in the code is not available. Interface A is not provided in step 2 of TimeSubject class getCityClock () this method, because Beijing clock objects are stored in TimeSubject class, so it's best class energy TimeSubject a getCityClock (String cityName) method as an interface, which accepts city names as an input parameter, and returns the corresponding trash city names city clock object; the interface to another does not provide the step 3 of CityClock class getCityTime () method I need to get a city clock, local time to print out. Even if none of these two interfaces, I am also here to actually use their calling code in main () method was to first write. "I trash said.
+ Return cityTime;
The time of Sydney is 19
"Okay, refactoring tools to change the name provided by IntelliJ trash very convenient ah, the local time is converted to UTC time it should be put where to do it? Because this conversion requires time difference UTC_OFFSET, and that five cities clock class has UTC_OFFSET, so this work by the five cities clock class to complete, and declare an abstract method in their parent class to regulate about the job. The name of an abstract method can be called convertCityTimeToUtcZeroTime (), which converts the local time UTC time. "I said.
+ Return cityTime -UTC_OFFSET;
- CityTime = utcZeroTime + UTC_OFFSET;
The time of Moscow is 5
"Oh, trash I'll go back updated code, but there are many places we need to be further modified, for example, I would have looked at those inside TimeSubject this class static member variables and member methods trash are not pleasing to the eye, it lacks distinction and global trash variables, perhaps the future is the source of some of the intractable problems, best able to get rid of the static. But this way, the HashMap member variables have shifted to its subclasses UtcTime, if this is the case, TimeSubject it seems no longer necessary. By the way, why would have TimeSubject work? Big Four are copying the class diagram of blame. If you really want such a change, that they have a lot of class diagrams need to update the place. "you say.

No comments:

Post a Comment