Skip to content

the thinkpod

where I think out loud

Menu
  • Timeline
Menu

Interview Question #1

Posted on December 12, 2013 by milad

So, as I mentioned before, I am going to post questions I think will be useful in interviewing applicants to a developer position in an average software development company. Here goes the first one.

Question

We see a class named AbstractShape with a method `redraw()` on it, with a given behavior already implemented. One of its subclasses, Circle, overrides this method and instead of coding a behavior of its own, throws an UnsupportedOperationException. What is the matter with this design? How can it be fixed?

Answer

So, to answer the question, it would be it is wrong to do that because in Object-oriented Design you should never subtract from functionality provided by a superclass. Now, the person designing that class probably was too lazy to branch a whole new level of hierarchy for this subclasses that explicitly needed the redraw functionality and implement it there, but it just isn’t right.

To correct it, we would have to extend AbstractShape into, say, AbstractRedrawableShape and move that redraw() method into that class. This way, classes that do support being redrawn will have the functionality, while we are not exposing the API for a class that simply will not support it.

Why the question?

Now, why would we ask an applicant this question. This question highlights several general areas of modern programming:

  • Object-oriented design principles and best practices
  • Understanding inheritance
  • The ability to correct a design mistake by pinpointing the problem and providing a meaningful solution.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I’m a tinkerer and engineer. Here, I write about all sorts of things.

Tags

administration algorithms application bash command blog book client clrs code cormen courses Data Structures domain eyeos firefox google google interview google interview series 1 google interview series 2 hello world host interview interview preparation java job learning linux mac phone screen poem Poetry preparation programming Projects repository Review script shell spring synopsis system management user management video windows 7 writing

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2021 the thinkpod | Built using WordPress and Responsive Blogily theme by Superb