Java Experiment three Agile development and XP practice

Source: Internet
Author: User
Tags coding standards delete key gettext version control system

First, the contents of the experiment

(i) Agile Development and XP

The purpose of the software development process is to improve the efficiency of software development, operation and maintenance, and improve the quality of software, customer satisfaction, reliability and maintainability of software. It is not enough to have ideas of all kinds of processes, and we have a series of tools to ensure that these ideas can operate efficiently in practice. A common formula is: Software engineering = development process + tools. Agile Development (development) is a human-centric, iterative, and progressive approach to development. "Agile Processes" are a collection of values and methodologies.

Among them, extreme programming (EXtreme programming,XP) is a new and fast software development method. The XP team uses on-site customers, special planning methodologies, and ongoing testing to provide rapid feedback and comprehensive communication:

    • XP is a methodology developed to target software that meets customer needs
    • XP is a practice-based software engineering process and thought
    • XP believes that code quality is more important than people generally think.
    • XP is ideal for small, responsible, self-motivated teams to develop software that requires uncertainty or rapid change

XP software development is what is expressed through the XP guidelines:

    • Communication: XP believes that communication between project members is key to the success of the project and regards communication as the main driver of coordination and cooperation in the project.
    • Simple: XP assumes that the future cannot be reliably predicted, and it is economically unwise to consider it now, so you should not think too much about the future but should focus on the urgent needs.
    • Feedback: XP considers the system itself and its code to be a reliable basis for reporting on the progress and status of the system development. The feedback of system development status can be used as a means to determine the progress of system development and determine the next development direction of the system.
    • Courage: It represents XP's view that people are one of the most important aspects of software development. In the development of a software product human participation throughout its entire life cycle, is the courage to eliminate the dilemma, let the team to the local optimal left behind, to achieve more significant goals. Demonstrates XP's basic trust in "people make projects successful".

The basis for successful use of a practice in an XP environment is presented through the rules of XP, including: Quick feedback, hypothesis simplicity, incremental changes, advocating for change, and quality of work.

XP software development is the cornerstone of XP activities, including: coding, testing, listening, design.

(ii) Coding standards

Programming standards include: Descriptive names, clear expressions, straightforward control flow, readable code and annotations, and the importance of consistently using certain rules and idioms when pursuing these content.

The program does not have the most basic indentation, it is difficult to read, this problem is easier to solve in eclipse, we can click on the Eclipse menu Source->format or use the shortcut key ctrl+shift+f in accordance with Eclipse specification indentation.

A very important part of the code standard is how to name packages, classes, variables, methods, and so on, so that you can name your code to go up a notch immediately. The general naming conventions in Java are:

    • To embody their own meanings.
    • Terms for packages, classes, variables
    • Method name with movable bin
    • Package name all lowercase, such as: IO,AWT
    • The first letter of the class name should be capitalized, such as: Helloworldapp
    • The first letter of a variable name is lowercase, such as: UserName

The first letter of the method name is lowercase: setName

(iii) Pair programming

Pairing programming is an important practice in XP. In pair programming mode, a pair of programmers work side-by-shoulder, equally, and in complementary way. They sit in front of a computer, facing the same monitor, working with the same keyboard and the same mouse. They analyze together, design together, write test cases together, encode together, do unit tests together, do integration testing together, write documents together, and so on. There are two roles in pairing programming:

    • The driver (Driver) is the person who controls the keyboard input.
    • The Navigator (Navigator) plays the role of pilotage and reminding.

How to pair programming, why pair programming, the focus is:

    • Drivers: Write design documents, conduct coding and unit tests, and other XP development processes.
    • Navigator: Review the driver's documentation, the driver's implementation of the development process such as coding, consider the coverage of unit tests, think about the need for and how to refactor, and help drivers solve specific technical problems.
    • Drivers and pilots constantly rotate their roles and do not work for more than an hour, and take 15 minutes off each hour of work. The navigator has to control the time.
    • Active participation. Any task is the responsibility of the two people, and the responsibility of all. There is no "My Code", "Your Code" or "his/her code", only "our code".
    • There are only horizontal gaps, and there is no level difference. They are pairs, and although they may have different levels of seniority, both sides have equal decision-making rights in terms of analysis, design, or coding.

Teamwork is a spirit that is emphasized in many places, and the smallest team is a one-to-two team, and the team spirit starts with pairing programming. The most important thing for people to get along with in social life is honesty, empathy and mutual benefit . There will be differences in pairing programming, how to cooperate more effectively to do things wrong .

(iv) version control

The collective ownership of XP means that everyone is responsible for all the code, which in turn means that everyone can change any part of the code. Pair programming contributes a lot to this practice: by working in different pairs, all programmers can see the full code. One of the main advantages of collective ownership is to increase the speed of the development process, because any programmer can fix it once there is an error in the code. This means that the code is placed in a place where everyone can easily get it, and we call it a code repository. This leads to another topic called versioning (version control).

Versioning provides a number of benefits for both teams and individuals.

    • versioning provides item-level      undo (undo)      Features:      Nothing is a finalized version, and any error must be easily rolled back. Let's say you're using the world's most complex word processing system. It has all the features you can think of, that is, the DELETE key is not supported. Imagine how cautious and slow you are when typing,      especially an oversized document near the end of the day, a careless will start again (imagine you select all the text, accidentally pressed the DELETE key, because there is no undo function, Had to re-enter). Edit text and versioning are the same, and anytime you need to roll back, whether it's one hours, a day, or a week, it makes your team work free and fast, and is confident about correcting bugs.
    • versioning allows multiple people to work on the same code,      just follow a certain control principle. There is no longer a case where one person overwrites another person's edited code, causing the person's modification to be invalid.
    • Versioning is also a project-level time machine, you can choose any time to accurately view the project at the time. This is useful for research and is the basis for reproducing a previously problematic release version of

(v) Reconstruction

Let's look at the concept of refactoring first:

Refactoring (refactor) is to change the structure within the software without changing the external behavior of the software, making it easier to read, easy to maintain, and easy to change.

One of the key prerequisites in refactoring is to "not change the external behavior of the software", which guarantees that we will not bring new bugs to the original system while reconstructing the original system, so as to ensure the security of the reconstruction. How to ensure that the software external behavior is not changed? The reconstructed code should be able to pass the unit test. How can you make it easier to read, easier to maintain, and easy to change? The design pattern gives the goal of refactoring.

(vi) Practical projects

1, the project brief: Edit a simple repeatedly watch the project small game.

Need to implement (1) a 6 row column of the main panel, show the number of participating games, (2) according to the player's choice of two number, to determine whether the two number is the same, if the same is eliminated, otherwise, until all the number is eliminated, the game is the end; (3) When the player cannot find the same number, you can use "Re-column" button to rearrange the current game, (4) The game starts again when the player chooses the "Come Again" button, (5) The game ends when the player chooses to exit the button.

2. Game Code

Package Lianliankan;
Import javax.swing.*;
Import java.awt.*;
Import java.awt.event.*;
public class Lianliankan implements ActionListener
{
JFrame MainFrame; Main panel
Container Thiscontainer;
JPanel Centerpanel,southpanel,northpanel; Sub-panel
JButton diamondsbutton[][] = new jbutton[6][5];//game button array
JButton Exitbutton,resetbutton,newlybutton; Exit, re-column, Start button
JLabel fractionlable=new JLabel ("0"); Score Label
JButton Firstbutton,secondbutton; Record two selected buttons separately
int grid[][] = new int[8][7];//save Game button position
Static Boolean pressinformation=false; Determine if a button is selected
int X0=0,y0=0,x=0,y=0,fristmsg=0,secondmsg=0,validatelv; Position coordinates of the game button
int i,j,k,n;//elimination Method control
public void init () {
Mainframe=new JFrame ("jkj repeatedly see");
Thiscontainer = Mainframe.getcontentpane ();
Thiscontainer.setlayout (New BorderLayout ());
Centerpanel=new JPanel ();
Southpanel=new JPanel ();
Northpanel=new JPanel ();
Thiscontainer.add (Centerpanel, "Center");
Thiscontainer.add (Southpanel, "South");
Thiscontainer.add (Northpanel, "North");
Centerpanel.setlayout (New GridLayout (6,5));
for (int cols = 0;cols < 6;cols++) {
for (int rows = 0;rows < 5;rows++) {
Diamondsbutton[cols][rows]=new JButton (string.valueof (grid[cols+1][rows+1));
Diamondsbutton[cols][rows].addactionlistener (this);
Centerpanel.add (Diamondsbutton[cols][rows]);
}
}
Exitbutton=new JButton ("exit");
Exitbutton.addactionlistener (this);
Resetbutton=new JButton ("Re-column");
Resetbutton.addactionlistener (this);
Newlybutton=new JButton ("One More Game");
Newlybutton.addactionlistener (this);
Southpanel.add (Exitbutton);
Southpanel.add (Resetbutton);
Southpanel.add (Newlybutton);
Fractionlable.settext (String.valueof (Integer.parseint (Fractionlable.gettext ()));
Northpanel.add (fractionlable);
Mainframe.setbounds (280,100,500,450);
Mainframe.setvisible (TRUE);
}
public void Randombuild () {
int randoms,cols,rows;
for (int twins=1;twins<=15;twins++) {
randoms= (int) (Math.random () *25+1);
for (int alike=1;alike<=2;alike++) {
cols= (int) (Math.random () *6+1);
rows= (int) (Math.random () *5+1);
while (grid[cols][rows]!=0) {
cols= (int) (Math.random () *6+1);
rows= (int) (Math.random () *5+1);
}
This.grid[cols][rows]=randoms;
}
}
}
public void fraction () {
Fractionlable.settext (String.valueof (Integer.parseint (Fractionlable.gettext ()) +100));
}
public void Reload () {
int save[] = new INT[30];
int n=0,cols,rows;
int grid[][]= new INT[8][7];
for (int i=0;i<=6;i++) {
for (int j=0;j<=5;j++) {
if (this.grid[i][j]!=0) {
SAVE[N]=THIS.GRID[I][J];
n++;
}
}
}
n=n-1;
This.grid=grid;
while (n>=0) {
cols= (int) (Math.random () *6+1);
rows= (int) (Math.random () *5+1);
while (grid[cols][rows]!=0) {
cols= (int) (Math.random () *6+1);
rows= (int) (Math.random () *5+1);
}
This.grid[cols][rows]=save[n];
n--;
}
Mainframe.setvisible (FALSE);
Pressinformation=false; Be sure to turn the button click information into the initial
Init ();
for (int i = 0;i < 6;i++) {
for (int j = 0;j < 5;j++) {
if (grid[i+1][j+1]==0)
Diamondsbutton[i][j].setvisible (FALSE);
}
}
}
public void Estimateeven (int placex,int Placey,jbutton BZ) {
if (Pressinformation==false) {
X=placex;
Y=placey;
Secondmsg=grid[x][y];
SECONDBUTTON=BZ;
Pressinformation=true;
}
else {
X0=x;
Y0=y;
fristmsg=secondmsg;
Firstbutton=secondbutton;
X=placex;
Y=placey;
Secondmsg=grid[x][y];
SECONDBUTTON=BZ;
if (fristmsg==secondmsg && Secondbutton!=firstbutton) {
Xiao ();
}
}
}
public void Xiao () {////The same situation can be eliminated. Careful analysis, there are no comments
if (x0==x && (y0==y+1| | y0==y-1)) | | ((x0==x+1| | x0==x-1) && (y0==y)) {//determine if adjacent
Remove ();
}
else{
for (j=0;j<7;j++) {
if (grid[x0][j]==0) {//Determine which button is empty for the first button
if (y>j) {//If the y-coordinate of the second button is greater than the y-coordinate of the empty button the first button is to the left of the second button
for (i=y-1;i>=j;i--) {//To determine the left side of the second button until there is no button in the middle of the first button
if (grid[x][i]!=0) {
k=0;
Break
}
else{k=1;}//k=1 instructions passed the first validation
}
if (k==1) {
Linepassone ();
}
}
if (y<j) {//If the y-coordinate of the second button is less than the y-coordinate of the empty button the first button is to the right of the second button
for (i=y+1;i<=j; i++) {//Judging the left side of the second button until there is no button in the middle of the first button
if (grid[x][i]!=0) {
k=0;
Break
}
else {k=1;}
}
if (k==1) {
Linepassone ();
}
}
if (y==j) {
Linepassone ();
}
}
if (k==2) {
if (x0==x) {
Remove ();
}
if (x0<x) {
for (n=x0;n<=x-1;n++) {
if (grid[n][j]!=0) {
k=0;
Break
}
if (grid[n][j]==0 && n==x-1) {
Remove ();
}
}
}
if (x0>x) {
for (n=x0;n>=x+1; n--) {
if (grid[n][j]!=0) {
k=0;
Break
}
if (grid[n][j]==0 && n==x+1) {
Remove ();
}
}
}
}
}
for (i=0;i<8;i++) {//Column
if (grid[i][y0]==0) {
if (x>i) {
for (j=x-1;j>=i; j--) {
if (grid[j][y]!=0) {
k=0;
Break
}
else {k=1;}
}
if (k==1) {
Rowpassone ();
}
}
if (x<i) {
for (j=x+1;j<=i;j++) {
if (grid[j][y]!=0) {
k=0;
Break
}
else {k=1;}
}
if (k==1) {
Rowpassone ();
}
}
if (x==i) {
Rowpassone ();
}
}
if (k==2) {
if (y0==y) {
Remove ();
}
if (y0<y) {
for (n=y0;n<=y-1; n++) {
if (grid[i][n]!=0) {
k=0;
Break
}
if (grid[i][n]==0 && n==y-1) {
Remove ();
}
}
}
if (y0>y) {
for (n=y0;n>=y+1; n--) {
if (grid[i][n]!=0) {
k=0;
Break
}
if (grid[i][n]==0 && n==y+1) {
Remove ();
}
}
}
}
}
}
}
public void Linepassone () {
if (y0>j) {//First button peer empty button on left
for (i=y0-1;i>=j; i--) {//To determine if there is a button between the first button and the left empty button
if (grid[x0][i]!=0) {
k=0;
Break
}
else {k=2;}//k=2 description passed the second validation
}
}
if (y0<j) {//First button peer empty button between and second button
for (i=y0+1;i<=j; i++) {
if (grid[x0][i]!=0) {
k=0;
Break
}
else{k=2;}
}
}
}
public void Rowpassone () {
if (x0>i) {
for (j=x0-1;j>=i; j--) {
if (grid[j][y0]!=0) {
k=0;
Break
}
else {k=2;}
}
}
if (x0<i) {
for (J=x0+1;j<=i; j + +) {
if (grid[j][y0]!=0) {
k=0;
Break
}
else {k=2;}
}
}
}
public void Remove () {
Firstbutton.setvisible (FALSE);
Secondbutton.setvisible (FALSE);
Fraction ();
Pressinformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionperformed (ActionEvent e) {
if (E.getsource () ==newlybutton) {
int grid[][] = new INT[8][7];
This.grid = grid;
Randombuild ();
Mainframe.setvisible (FALSE);
Pressinformation=false;
Init ();
}
if (E.getsource () ==exitbutton)
System.exit (0);
if (E.getsource () ==resetbutton)
Reload ();
for (int cols = 0;cols < 6;cols++) {
for (int rows = 0;rows < 5;rows++) {
if (E.getsource () ==diamondsbutton[cols][rows])
Estimateeven (Cols+1,rows+1,diamondsbutton[cols][rows]);
}
}
}
public static void Main (string[] args) {
Lianliankan llk = new Lianliankan ();
Llk.randombuild ();
Llk.init ();
}
}

3, the Group Division of Labor (Group members: 20135116 Wang Wei Blog address: http://www.cnblogs.com/wwy-20135116/, 20135109 Gao Yi Tong)

Gao Yi: Write judgment operation, determine whether the player selected two number is consistent, if the same is eliminated, otherwise the interface is unchanged.

Wang Wei: Write the settings for the page space, such as "re-column", "Come Again", "exit" button in the game.

4. Test results show

(vii) Experimental time

Steps

Take

Percentage

Demand analysis

1h

25%

Design

30min

12.5%

Code implementation

1.5min

37.5%

Test

0

0%

Analysis Summary

1h

25%

(eight) experimental summary

learn from this experiment the raname of refactoring: How to modify a name. It is now quick and easy to modify the name of a program when it is accidentally misspelled, or if it needs to be modified to make it more meaningful. I think it is very practical and meaningful to write the code later. I also learned to refactor the encapsulation functionality, to encapsulate member variables, and to Source->generate toString () ... Generates a ToString method for the student class. This optimizes the code for the experiment and makes the code more concise and straightforward. In the experiment, I also encountered a lot of problems, such as in the refactoring of the package function, because there is no time to select the age, name, ID to make the code encapsulation failed, but by consulting the students to finish the final problem is solved.

This Java experiment let me learn to optimize the code, not only to make users look simple and comfortable, but also to add the rate of completion of the code, I have benefited from this experiment.

Java Experiment three Agile development and XP practice

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.