Adobe Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




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

Just make the copy constructor and the assignment operator protected for the base class

- alexander July 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it's OK to make them private too, right? I mean, it'll prevent the subclasses from being able to have a default = operator and copy constructor, but that makes sense: if a class is uncopiable, its subclasses should be too.

- eugene.yarovoi July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If they're protected, the subclass will be able to make copies of instances of the base class.

- eugene.yarovoi July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@eugene If you make all the constructors of the base class protected then you can only call those constructors for base class initialization when calling derived class constructor using this pointer, There's no way for you to create its object, so also you can't copy.
I think it is better than making private.
Since by making private you will make derived classes uncopyable too, which is not what we want

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

Why not? If a base class is uncopiable, it makes sense for derived classes to also be so, because a derived class includes the superclass in some sense. Also, you can still override the = operator for subclasses and define code for copying the objects, where appropriate. The issue I'm seeing is that if you make the copy constructors protected, you're introducing the possibility that someone implementing a subclass will create instances of the base class and copy them, thus bypassing the uncopiable rule.

- eugene.yarovoi July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

By making instances of base class what do you mean, creating objects of base class i.e. you will have base class objects as member objects in derived class.

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

I'm saying that if the copy constructors and assignment operations are protected, the subclasses could then contain code like BaseClass b = new BaseClass(); BaseClass b2 = b;

Reading the problem description, this should not be allowed, it seems. That's why I think they should be private. Yes, that does make the subclasses uncopiable unless they implement their own copy constructor and assignment operators.

- eugene.yarovoi July 08, 2012 | Flag


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