This application is an example of the SOLID principles and encapsulation violation. During running it can fall down, don’t do what it should and so on. The main task is to refactor the code according to the SOLID principles. The idea of this application (what is should do) is described next.
The Robot
Preconditions: You have got a robot without a battery and charging device, two empty not rechargeable batteries (old type and new type) and unplugged charging device.
Task: Create a program that can control the robot and display an information about it.
Goal: Make the robot to reach the wall in 27 meters from the start and show the level of the battery
The Robot has:
• Battery
• Charging device
• Indicators
The Robot can:
• Be turned on\off
• Be on charging
• Move
• Reach the destination (set against the wall)
Limitations:
It can’t be turned on without battery or when the battery discharged. It can’t move while charging. When one battery is discharged, you need to change it to another one.
The new type Battery has:
• Be plugged in\out
• Level of charge in percent
• Charge indicator (lights when fully charged)
The Battery can:
• Increase its charge level when it is in the robot and the charging device is plugged in(charging speed 20%\sec)
• Decrease its charge level whet it is plugged in and while moving (the charge level falls down with a speed 5%\m )
The old type Battery has:
• Level of charge in percent
The Battery can:
• Be plugged in\out
• Increase charge level when it is in the robot and the charging device is plugged in(charging speed 10%\sec)
• Decrease charge level whet it is plugged in and while moving (the charge level falls down with a speed 5%\m )
The charging device has:
• Indicator
The charging device can:
• Be plugged in\out
The program’s UI has:
Indicators:
• Battery charged\discharged
Status field:
• Turned on/off
• Battery missing
• Battery charge status
• Robot movement status
• Reached the destination
Buttons:
• Turn on\off
• Plug in new type battery
• Plug in old type battery
• Plug in\out the charging device
• Move