I was recently at a job interview where I was asked this question(More or less as I don't remember the full question. This is the out of the top of my head):
You need to make a simple tcp server that can be accessed through puTTy (or any other client for that matter).
Once you are in, you need to write:
login < username > (Doesn't matter what username).
once you are logged in you have 3 operations you can do:
showDevices - will return a list of devices (Currently we have lamp and an airconditioner) - we can write mock objects. Let's assume they have a number Id.
Switch < deviceId > < on|off > - sets the device on or off.
SetValue < deviceId > < double > - set's the device's ranged value (Air condition tempature)
Important things:
Separation - Separate the logic and communication layer. We work with a telenat server now but we will want to switch to an http server in the future. The process should be easy.
Extensibility- We currently have 4 operations (login, showDevices, Switch, SetValue) - write the server so it would be very easy for other programmers to add another operation. The code should be self-explanatory
The assignment could have been written in any language. I tried writing it in C# until I was stuck and couldn't continue. I had the tcp server running but could not really think of the full solution.
-
How do I best seperate between the communication and the logic layer?
-
Is there some sort of design pattern I should implement for adding commands easier? (I looked at the command design pattern and I couldn't figuere out if it was meant for this kind of situation)
Anything that can actually direct me in the right track will be appreciated.
Thanks!
Aucun commentaire:
Enregistrer un commentaire