Sunday, February 8, 2015

Day 3: Identify Behaviors

Today, game is an important industrial of software, one of most important features that a game must have is the extensible capacity. As an architect, you know the meaning of “implement into interface not into implementation”, so you must:


Create an interface for actor that can do :
- forward()
- jump()
- blink()

Code:


public class Game implements Movement
{
    private Square player;
    
    public Game()
    {
        player = new Square();
        player.makeVisible();
    }


    public void Forward() {
        player.moveRight();
    }
    
    public void Backward() {
        player.moveLeft();
    }
    
    public void Jump() {
        player.slowMoveVertical(-100);
        player.slowMoveVertical(100);
    }
    
    public void BlinkForward() {
        player.makeInvisible();
        player.moveHorizontal(150);
        player.makeVisible();
    }
    
    public void BlinkBackward() {
        player.makeInvisible();
        player.moveHorizontal(-150);
        player.makeVisible();
    }
}


Make an explanation of “implement into interface not into implementation” for your team
What is advantage or disadvantage of using interface in software development?
  • Advantages:
    • Những class khi implement từ interface sẽ tuân theo những gì (methods..) mà interface đã định ra.
  • Disadvantages
    • Nếu 1 class khi implement từ interface không muốn sử dụng 1 số phương thức ( Methods) có sẵn trong interface vẫn phải sử dụng.



No comments:

Post a Comment