Microsoft Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
Remote newRemote = new Remote();
Button newButton = new Button(color, name);
Battery newBattery = new Battery(someVolt);
//changes the battery
newRemote.updateBatteries(newBattery);
//add a button to its internal hashmap that has name associated with buttons.
newRemote.addButton(newButton);
//to press a button on remote you can say
newRemote.getButton("power").execute();
So the above end code will tell you that you need a Button class, a Battery class.
To take it further. The Button class can have a execute() function. Battery could have getRemainingPower() function.
Base class button{
//common setters and getter variables
//common methods declared abstract and called virtually
}
class channel extends button {
//channel specific getters and setters and methods
}
class volume extends button {
//volume specific getters and setters and methods
}
class power extends button{
//power specific getters and setters and methods
}
//Not sure of the below two.
class battery{
}
class remote{
}
Classes you could have are..Also you could follow the Observer pattern..
/**
*All actions are funneled through this class..gets the actionStr and publishes it..
*/
class Remote implements Observable { make,model,.. , List<Button>, publish() }
class Button { name, actionStr }
/**
Set of common actions in the Action class and Controller also observes the changes to button's state (which is published by Remote)
*/
class Controller extends Action implements Observer { .. sendSignals() {..} }
- Ajeet October 31, 2013