java - Interview Question: Design pattern to control behaviour of Fridge -


recently in 1 of interview asked interesting question.

you have fridge has been put organization use of employees. observed employees not opening or closing door of fridge. e.g. kicks close, might push more it's needed close it. have decided control these 2 actions. create design problem.

i come following solution not satisfied it.

  1. define 2 states open , close fridge object. these objects of fridge only.
  2. open() , close() control behavior creating these objects. off-course final.
  3. every operation check state of fridge if not in valid state throw unsupportedoperation exception.

is right solution or there can better way?

i calculate speed , acceleration of door. check against min , max threshold values. when it's closed , closes it, door has have minimum speed , shouldn't go above max speed, etc...


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -