Apple Interview Question for Software Engineer / Developers


Team: Data Mining
Country: United States




Comment hidden because of low score. Click to expand.
5
of 5 vote

As per LSP (Liskov's substitution principal) inheritance is wrong choice for this problem. Strategy and composition is right choice. So break down draw into different strategy classes. DrawLegsStrategy etc. Call appropriate strategy classes from Lion and Tiger draw methods.

- raj May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Perfect

- Ashupriya August 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is nice insight! but how will both Tiger and Lion classes be placed ? Will they be independent clients of DrawLegsStrategy, DrawManeStrategy etc... ?

- spiderman August 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Full Marks.. on spot mate

- Chandan October 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why would you use composite pattern here?

- BJ July 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

template pattern

- suwei19870312 July 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 4 vote

Break down the draw method into smaller pieces, Draw will use these methods to acheive full drawing. drawHead,drawBody,drawMane,drawbodycolor, have all the methods as protected.
inherite the lion class to tiger make draw virtual. override Draw method, call approrpiate primitive methods in tiger draw. if needed have extra methods in tiger class.

- Anonymous May 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Inheritance is a bad choice here,
go for composition,

Since "Tiger is A lion" is not true, Don't use Inheritance,

- Ashupriya August 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

This is an eample of Decorator pattern

- Anonymous June 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

how can you reduce functionality through decorator pattern?

- aditya July 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is no question. You can check the programatic solution in Java at here

http:\\ideone.com\0qghO

- strongfrakk April 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question is, how would you implement the Tiger class, given that you already implemented the Lion class.

- apple-maybe? April 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

inherit and override ?

- Anonymous April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Use Decorator to add strips and remove mane.

- NT April 24, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Break down the draw method into smaller pieces, Draw will use these methods to acheive full drawing. drawHead,drawBody,drawMane,drawbodycolor, have all the methods as protected.
inherite the lion class to tiger make draw virtual. override Draw method, call approrpiate primitive methods in tiger draw. if needed have extra methods in tiger class.

- pa1 May 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Break down the draw method into smaller pieces, Draw will use these methods to acheive full drawing. drawHead,drawBody,drawMane,drawbodycolor, have all the methods as protected.
inherite the lion class to tiger make draw virtual. override Draw method, call approrpiate primitive methods in tiger draw. if needed have extra methods in tiger class.

- pa1 May 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tempalte Design pattern can be used in this case.We can break down the draw method in several parts.Create an abstract class with the draw methos containing the various steps in the draw method.
For example

abstract class DrawAnimal
{ final void public draw()
{
drawHead();
drawBody();
drawMane();
drawStripes();
}

public void drawBody()
{
//Put code

}

public void drawHead()
{
//code
}

public void drawMane()
{
}

public void drawStripes()
{
}
}

Implement this abstract class in Lion and tiger and in case of Tiger override the methods drawmane and drawstripes.

- Anonymous November 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Template Design Pattern can be used

- Anonymous November 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Composition is a good idea.

The other solution i can think of is create an abstract class called CatSpecies and give all the methods there like drawHead(), drawLegs() and abstract method like draw(), also give the properties which are common.

Then derive two classes from it as Lion and Tiger and then give them individual properties and override draw().

- vidhi.thakrar October 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If I guess this right, they are looking for Decorator design pattern here. Something like below.

WildAnimal -> Interface
Cat -> implements WildAnimal and draw for cat excluding mane and stripes
CatDecorator -> Decorates cat
TigerDecorator -> Concrete decorator calls cat's draw method and appends stripes
LionDecorator -> Concrete decorator calls cat's draw method and appends mane.

- Puru April 15, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More