From: Jordan Marr on
I just took one of those online programming tests (where you have a
few minutes to answer each question, multiple choice). One of the OOP
questions threw me for a loop.

The code sample showed three classes: car, engine and piston. The car
'had an' engine, and the engine 'had a' collection of pistons. Then
the car class had a Start() void that delegated work to the engine
class, which delegated work to the pistons. None of the three classes
had a base class.

The question asked what OO concept was being demonstrated in the code
sample:
delegation, composition, polymorphism, combination, or inheritance.

It seemed to me that the answer could be either delegation or
composition. Generally, the two go hand in hand, but there was only
one "correct" answer. I went with "composition", because it seemed
likely to be listed before delegation as an OOP concept.

Thoughts?

Jordan

From: lbonafide on
On Apr 4, 11:43 am, Jordan Marr <jnm...(a)hotmail.com> wrote:
> I just took one of those online programming tests (where you have a
> few minutes to answer each question, multiple choice).  One of the OOP
> questions threw me for a loop.

Was this a Brainbench ("Braindead") test?

>
> The code sample showed three classes: car, engine and piston.  The car
> 'had an' engine, and the engine 'had a' collection of pistons.  Then
> the car class had a Start() void that delegated work to the engine
> class, which delegated work to the pistons.  None of the three classes
> had a base class.
>
> The question asked what OO concept was being demonstrated in the code
> sample:
> delegation, composition, polymorphism, combination, or inheritance.
>
> It seemed to me that the answer could be either delegation or
> composition.  Generally, the two go hand in hand, but there was only
> one "correct" answer.  I went with "composition", because it seemed
> likely to be listed before delegation as an OOP concept.

I think you chose correctly, though I see your point. An example of
delegation without composition would be if one of your methods or
member functions constructed an object (e.g. a std::string), used it
for some task, and then let it go out of scope when the function
returned.

Anyway, I hate those tests. Was this for a job?
From: H. S. Lahman on
Responding to Marr...

> I just took one of those online programming tests (where you have a
> few minutes to answer each question, multiple choice). One of the OOP
> questions threw me for a loop.
>
> The code sample showed three classes: car, engine and piston. The car
> 'had an' engine, and the engine 'had a' collection of pistons. Then
> the car class had a Start() void that delegated work to the engine
> class, which delegated work to the pistons. None of the three classes
> had a base class.
>
> The question asked what OO concept was being demonstrated in the code
> sample:
> delegation, composition, polymorphism, combination, or inheritance.
>
> It seemed to me that the answer could be either delegation or
> composition. Generally, the two go hand in hand, but there was only
> one "correct" answer. I went with "composition", because it seemed
> likely to be listed before delegation as an OOP concept.

It depends upon whose definition of 'composition' you use. In an OO
context it usually refers either: (A) to aggregation through one object
being embedded in another's implementation; or (B) to an object's
definition being defined (composed) through multiple inheritance. So I
would go with delegation.

FWIW, I don't like the example. For example, association roles like
"had" are very often a symptom of lazy problem space abstraction. Also,
at the level of abstraction where Piston is important, Car should
probably be collaborating with a StarterMotor rather than Engine.

--
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl(a)pathfindermda.com
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info(a)pathfindermda.com for your copy.
Pathfinder is hiring:
http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH
From: Jordan Marr on
On Apr 4, 2:43 pm, lbonaf...(a)yahoo.com wrote:
> On Apr 4, 11:43 am, Jordan Marr <jnm...(a)hotmail.com> wrote:
>
> > I just took one of those online programming tests (where you have a
> > few minutes to answer each question, multiple choice).  One of the OOP
> > questions threw me for a loop.
>
> Was this a Brainbench ("Braindead") test?
>
>
>
> > The code sample showed three classes: car, engine and piston.  The car
> > 'had an' engine, and the engine 'had a' collection of pistons.  Then
> > the car class had a Start() void that delegated work to the engine
> > class, which delegated work to the pistons.  None of the three classes
> > had a base class.
>
> > The question asked what OO concept was being demonstrated in the code
> > sample:
> > delegation, composition, polymorphism, combination, or inheritance.
>
> > It seemed to me that the answer could be either delegation or
> > composition.  Generally, the two go hand in hand, but there was only
> > one "correct" answer.  I went with "composition", because it seemed
> > likely to be listed before delegation as an OOP concept.
>
> I think you chose correctly, though I see your point.   An example of
> delegation without composition would be if one of your methods or
> member functions constructed an object (e.g. a std::string), used it
> for some task, and then let it go out of scope when the function
> returned.
>
> Anyway, I hate those tests.  Was this for a job?


Yes, I had to take a C# test and an ASP.NET test for a job. The
employer said I could not be a senior level developer since I
graduated in '04 and have 5 years experience with C# / ASP.NET.
Nevermind the fact that .Net is only 6 years old, and that my last 4
contract jobs have been senior level positions.

I'm not a big fan of timed tests. It's really disconcerting to see
the 3 minute javascript timer counting down on each question.
Multiply that by 40 questions, and it becomes an anxiety laden 2
hours!

Still, I did fairly well. My percentile for C# was 90th, and for
asp.net was 98th!
Unfortunately, I cannot see which ones I missed. It did list OOP as a
strong point though, but I'm sure some of the people in this group
could have made some much harder OO questions. :)

Jordan
From: Lloyd Bonafide on
Jordan Marr <jnmarr(a)hotmail.com> wrote in news:58cb29b0-71e0-4ec2-86f2-
a3d234666677(a)2g2000hsn.googlegroups.com:

> It did list OOP as a
> strong point though, but I'm sure some of the people in this group
> could have made some much harder OO questions. :)

Let me guess:

What is polymorphism?

What is the difference between inheritance and composition?

Those are the ones I usually get. :-)