Amazon Interview Question for Software Engineer / Developers


Country: India




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

Containment and Aggregation is to achieve re-usability through object composition.

Containing Object never exposes internal object to clients where as aggregation delegates responsibility for calls directly to internal component.




delegate responsibility for calls directly to internal
component

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

just to add more explanations: containment is used when the outer object needs to modify the behaviour of the inner object.

for the second part of the question: when the outer object dies, the contained inner object is also destroyed (since its not exposed to the outer world)

while in case of aggregation, it's not necessarily true:
you just decrease a reference counter since same object can be aggregated by other objects as well

- 111 February 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Interfaces are abstract C++ classes that has mostly all functions as pure virtual functions and generally has name starting with "I". IAuto, IGame, IPhone etc...
Interfaces define all the basic functionality a particular COM component should have.

COM component is a C++ class that inherits/implements these Interfaces.
This COM component exposes different methods using its Interfaces
eg:
class IPhone
{
public :
virtual void LiftUp()==0;
virtual void PutDown()==0;
};
ISmartPhone
{
public :
virtual void Touch();
};
class MyPhone : public IPhone, public ISmartPhone
{
public :
void LiftUp()
{}
void PutDown()
{}
void Touch()
{}
};


class MySmartPhone
{
public :
MyPhone* m_pPhone;
//This is aggregation where you define a Class pointer and leaves the decision of allocation and release of memory dynamically.
For which you need to call CoCreateInstance() and Release() methods when you use it.The client code that uses it, needs to take care of allocating memory and releasing it.

};




Containment explained :
This is achieved by defining a smart pointer of a COM component class.
Advantage :
Memory allocation and de allocation is taken care by the mechanism. User/client code need not worry about it.
eg:
class MySmartPhone
{
public:
MyPhone m_Phone; //This is contentment as memory is allocated statically and client code doesn't need to bother about memory allocation and releasing it.
};

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

Interfaces are abstract C++ classes that has mostly all functions as pure virtual functions and generally has name starting with "I". IAuto, IGame, IPhone etc...
Interfaces define all the basic functionality a particular COM component should have.

COM component is a C++ class that inherits/implements these Interfaces.
This COM component exposes different methods using its Interfaces
eg:
class IPhone
{
public :
virtual void LiftUp()==0;
virtual void PutDown()==0;
};
ISmartPhone
{
public :
virtual void Touch();
};
class MyPhone : public IPhone, public ISmartPhone
{
public :
void LiftUp()
{}
void PutDown()
{}
void Touch()
{}
};


class MySmartPhone
{
public :
MyPhone* m_pPhone;
//This is aggregation where you define a Class pointer and leaves the decision of allocation and release of memory dynamically.
For which you need to call CoCreateInstance() and Release() methods when you use it.The client code that uses it, needs to take care of allocating memory and releasing it.

};




Containment explained :
This is achieved by defining a smart pointer of a COM component class.
Advantage :
Memory allocation and de allocation is taken care by the mechanism. User/client code need not worry about it.
eg:
class MySmartPhone
{
public:
MyPhone m_Phone; //This is contentment as memory is allocated statically and client code doesn't need to bother about memory allocation and releasing it.
};

- SantoshRameshraoDeshmukh February 15, 2012 | 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