what is the difference between abstract class and pure abstract class?

V

Victor Bazarov

and what is object delagation, and how it can implemented?

There is no concept of "pure abstract class" in C++. So, I'd say there
is no difference. Of course, one could always pull some concept by the
ears and say that a "pure abstract class" is an abstract class that has
no data members. Is that good enough to deduce the difference?

Have you tried searching the web for "pure abstract class" and "object
delegation" (yes, it's spelled a bit differently)? If not, what is
stopping you? If you did, what have you found? Is there something in
those web pages you don't understand? "Delegation" is implemented in
C++ through inheritance or containment. Slap polymorphism on top of
it and you get a very powerful run-time mechanism for extending object's
functionality.


V
 
N

Noah Roberts

Victor said:
There is no concept of "pure abstract class" in C++. So, I'd say there
is no difference. Of course, one could always pull some concept by the
ears and say that a "pure abstract class" is an abstract class that has
no data members. Is that good enough to deduce the difference?

A pure abstract class is an abstract class with no implemented members.

class Abstract
{
public:
virtual void f1() = 0;
virtual void f2() {}
};

class PureAbstract
{
public:
virtual void f1() = 0;
virtual void f2() = 0;
};

The "pure abstract" is really nothing but an interface def.

It seems like a silly distinction but there are arguments against the
first version in favor of always doing the second. The language makes
no such distinction...it is purely a design issue.

Not sure if a "pure abstract" has data members...I think not.
 
R

Rolf Magnus

and what is object delagation, and how it can implemented?

Please always put the complete question into the body. I was quite irritated
by the "and" at the beginning, until I saw that the subject line already
contains another question.

An abstract class is one that has at least one pure virtual member and thus
can't be instantiated directly. There is no such thing as "pure abstract
class" in C++.
Delegation means that an object doesn't handle a request, but rather
delegates it to another special handler object. This way, you can plug
different handlers to your object to get different behavior.
 
R

Rolf Magnus

Noah said:
A pure abstract class is an abstract class with no implemented members.

class Abstract
{
public:
virtual void f1() = 0;
virtual void f2() {}
};

class PureAbstract
{
public:
virtual void f1() = 0;
virtual void f2() = 0;
};

The "pure abstract" is really nothing but an interface def.

It seems like a silly distinction but there are arguments against the
first version in favor of always doing the second.

IMHO, it's a big advantage of C++ over some other modern OO languages that
it actually permits the first version. Sometimes, I want an abstract class,
but I sill want some stuff implemented there. Otherwise all derived class
would have to implement the same behavior over and over again. That would
result in code duplication.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top