OO Design Interview Approach

C Spire Wireless SXvh05
Feb 11 17 Comments

In OO design interviews, how do you approach the problem? Do you draw out any use case or class diagrams? Do you just write some notes and go straight to code? Just curious.

Question recently asked was:

Design a coffee maker. It can serve 3 drinks ( latte, frap, coffee ). You can ask it what types of coffee does it serve. It also can display when it needs to be serviced.

comments

Want to comment? LOG IN or SIGN UP
TOP 17 Comments
  • New
    nfs

    New

    PRE
    Booking.com
    nfsmore
    1. you should create a base object called HotDrink from which all drinks inherit and make sure the base object implements drinkable interface.
    In hot drink you should create shared variables and methods you want to be shared with other hot drinks.

    2. the coffee machine should be based on the factory design pattern and create the drinks.
    The factory should contain an arraylist of all drinks they serve or even better an ENUM.
    It should also contain a date variable and status variable.

    That's basically it in a nut shell.
    Feb 11 4
    • New ktFx33
      Good stuff.. do you have a resource where we could read up on applying oo principles on examples like this
      Feb 11
    • eBay / Eng bluechi
      Why does HotDrink need to implement an interface?
      Feb 11
    • New
      nfs

      New

      PRE
      Booking.com
      nfsmore
      @ktFx33, hmmm im nkt sure, probably online. I would say you can also start making up examples of different things in life and start coding them at home, i used to do that for fun (go figure ☺ )
      Feb 12
    • New
      nfs

      New

      PRE
      Booking.com
      nfsmore
      @bluechi so all the objects inheriting it will have the method drink(). It's not a must but, if for example they would also expand the coffee machine to make soda, you can create ColdDrink object that implements drinkable as well.
      Feb 12
  • Bloomberg cubiclefun
    Is it for amazon or google?
    Feb 11 2
    • C Spire Wireless SXvh05
      OP
      Neither. Just did one last week and felt stuck . Wanted to see if there is a better approach I can take next time.
      Feb 11
    • Why? Does the answer differ based on Amazon or Google?
      Feb 11
  • Verizon SuckinWood
    What was the ask? I think then we can better help then.
    Feb 11 6
    • Verizon SuckinWood
      Where were your struggles at, at the surface it appears rather straight forward. What was a major roadblock for you to think through?
      Feb 11
    • Intel bxsnlns
      Ah. Use cases & class diagram. Build interface with methods. Review solid principles if you are still lost.
      Feb 11
    • Verizon SuckinWood
      I tend to draw picture to be honest, after all, it is objects.

      I tend to backspace the code less often when I have a picture drawn.
      Feb 11
    • C Spire Wireless SXvh05
      OP
      My struggle was that I didn't have a method to follow. I would get too deep on one part and maybe forget some other shallow part. It was kind of a mess.
      Feb 11
    • Verizon SuckinWood
      KISS. It sounds like to me that question wasn’t as much about detail as it was your ability to get a simple design going.

      Don’t over engineer the simple stuff :). I wouldn’t sweat it. In my opinion, OO is misunderstood, hardly ever used correctly, and takes years of practice to full understand it, and even then you’ll still suck.

      Think about it in tiny parts. You have the control, maybe the brew button, a display, etc.

      Break it down. Although I’m already losing my own thought train, which is why the pics and diagrams are so important.
      Feb 11
  • Uber yTzY24
    What a stupid question! You don’t make coffee makers using OOP; you make them with plastic, metal, and glass. The correct approach would be to end the day of interviews early.
    Feb 11 0
  • New / Mgmt VSwf01
    What in the world type of question is that? Anyways, I'll personally represent that as a state machine.
    Feb 11 0