Created
June 21, 2015 21:03
-
-
Save avh4/2b953cdf40d91bd75f1a to your computer and use it in GitHub Desktop.
Cohesion example 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Game { | |
int ballX = 0; | |
int ballY = 0; | |
public void draw(Graphics g) { | |
// draw the background | |
g.setColor(new Color(178, 223, 224)); | |
g.fillRect(0, 0, 800, 600); | |
// draw the ball | |
g.setColor(new Color(155, 93, 169)); | |
g.fillOval(ballX, ballY, 8, 8); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ball { | |
int x = 0; | |
int y = 0; | |
public void drawBackground(Graphics g) { | |
g.setColor(new Color(178, 223, 224)); | |
g.fillRect(0, 0, 800, 600); | |
} | |
public void drawBall(Graphics g) { | |
g.setColor(new Color(155, 93, 169)); | |
g.fillOval(x, y, 8, 8); | |
} | |
} | |
class Game { | |
Ball ball = new Ball(); | |
public void draw(Graphics g) { | |
ball.drawBackground(g); | |
ball.drawBall(g); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ball { | |
int x = 0; | |
int y = 0; | |
public void draw(Graphics g) { | |
g.setColor(new Color(155, 93, 169)); | |
g.fillOval(x, y, 8, 8); | |
} | |
} | |
class Game { | |
Ball ball = new Ball(); | |
public void draw(Graphics g) { | |
drawBackground(g); | |
ball.draw(g); | |
} | |
public void drawBackground(Graphics g) { | |
g.setColor(new Color(178, 223, 224)); | |
g.fillRect(0, 0, 800, 600); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment