编程代考 Property of Penn Engineering

Property of Penn Engineering

How Do We Refactor

Copyright By PowCoder代写 加微信 powcoder

Property of Penn Engineering

• Improving the internal quality of existing code

• Do this carefully! Always test after each change

• Always be on the lookout for code smells

Refactoring

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List a = new LinkedList();
public void add_player(String name) {

this.name = name;
a.add(new Player(name));

public void go() {

clock++; // increment clock
for (Player p : a) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

How Can We Refactor This Code?

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List a = new LinkedList();
public void add_player(String name) {

this.name = name;
a.add(new Player(name));

public void go() {

clock++; // increment clock
for (Player p : a) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

How Can We Refactor This Code?

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List a = new LinkedList();
public void add_player(String name) {

this.name = name;
a.add(new Player(name));

public void go() {

clock++; // increment clock
for (Player p : a) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

1. Use Meaningful Identifier Names

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List players = new LinkedList();
public void add_player(String name) {

this.name = name;
players.add(new Player(name));

public void go() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

1. Use Meaningful Identifier Names

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List players = new LinkedList();
public void add_player(String name) {

this.name = name;
players.add(new Player(name));

public void go() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

1. Use Meaningful Identifier Names

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List players = new LinkedList();
public void add_player(String name) {

this.name = name;
players.add(new Player(name));

public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

1. Use Meaningful Identifier Names

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List players = new LinkedList();
public void add_player(String name) {

this.name = name;
players.add(new Player(name));

public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

2. Adhere to Code Conventions

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

this.name = name;
players.add(new Player(name));

public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

2. Adhere to Code Conventions

Property of Penn Engineering

public class MyFunGame {
private String name;
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

this.name = name;
players.add(new Player(name));

public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

3. Remove Unnecessary Code

Property of Penn Engineering

public class MyFunGame {

public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

3. Remove Unnecessary Code

Property of Penn Engineering

public class MyFunGame {

public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready()==true)p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

3. Remove Unnecessary Code

Property of Penn Engineering

public class MyFunGame {

public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready())p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

3. Remove Unnecessary Code

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready())p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

3. Remove Unnecessary Code

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

clock++; // increment clock
for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready())p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

4. Remove Unnecessary Comments

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready())p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

4. Remove Unnecessary Comments

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {
if(p.isAlive()&&p.points()> 0&&p.ready())p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

5. Use Indentation

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {

if(p.isAlive()&&p.points()> 0&&p.ready())p.move();
else if (p.isAlive() && p.points() > 0) p.pause();

5. Use Indentation

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {

if(p.isAlive()&&p.points()> 0&&p.ready())

else if (p.isAlive() && p.points() > 0)
p.pause();

5. Use Indentation

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {

if(p.isAlive()&&p.points()> 0&&p.ready())

else if (p.isAlive() && p.points() > 0)
p.pause();

6. Use Whitespace

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {

if (p.isAlive() && p.points() > 0 && p.ready())

else if (p.isAlive() && p.points() > 0)
p.pause();

6. Use Whitespace

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {

if (p.isAlive() && p.points() > 0 && p.ready())

else if (p.isAlive() && p.points() > 0)
p.pause();

7. Don’t Repeat Yourself

Property of Penn Engineering

public class MyFunGame {
public int clock = 0;
protected List players = new LinkedList();
public void addPlayer(String name) {

players.add(new Player(name));
public void playOneStep() {

for (Player p : players) {

if (p.isAlive() && p.points() > 0) {
if (p.ready())

else p.pause();

7. Don’t Repeat Yourself

Property of Penn Engineering

• Improving the internal quality of existing code

• Do this carefully! Always test after each change

• Always be on the lookout for code smells

Refactoring

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com