Hi, I am a fresh graduate from Diploma in IT. Recently I just went to an interview. The interviewer gave me a question. The question is, he want me to code him a program, base on a snake game(quite popular in nokia oldies handphone). Not a full program actually but just a part only. You have 4 buttons for go left, go right, go up, and go down. It also have a calculationOfAxis per second for the movement rate of the snake and also a callSnake function for the GUI. Below is a rough example of the function.
moveUp(){...}
moveDown(){...}
moveRight(){...}
moveLeft(){...}
calculationOfAxis(x-axis, y-axis){
callsnake()
}
Then he ask me that if I want to change the GUI of the snake, what should I do? Then I replied him just change the codes of the snake to car. Then he told me that wouldn't it be better if you do it in another way than keep changing your codes? Then i came out a solution which is the code below.
public class Parents(){
moveUp(){....};
moveDown(){...};
moveRight(){...};
moveLeft(){...};
calculationOfAxis(x-axis, y-axis){...};
}
public class Child extends Parents(){
super(moveUp(),moveDown(),moveRight(),moveLeft(),c alculationOfAxis(x,y);
callcar();
}
After that I said you can call whatever you want in the child class [eg: callShip(), callMotor()]
Then he said my answer is acceptable but not the efficient way. So, he gave me a situation which he said that his company project roughly consists of millions of code. He want a method to add a new features in the project without the need of editing the existing code and can guarantee it will work with the old codes. He also said that he want to test the new codes ONLY. You can neglect the old codes for the sake of saving time.
Well, that is where I am stuck now. Honestly I don't really quite get what he want. So, hopefully someone can show me the solution of this question.