| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Wat" |
| Date: |
04 Dec 2004 12:40:59 PM |
| Object: |
Abstract class derived from concrete class? |
Is it doable to have a abstract class derived from a concrete class?
Is it a good practice? If so in what situation is this necessary?
Thanks in advance!
.
|
|
| User: "Cy Edmunds" |
|
| Title: Re: Abstract class derived from concrete class? |
04 Dec 2004 03:04:47 PM |
|
|
"Wat" <welwat@hotmail.com> wrote in message
news:%wnsd.89794$7i4.65305@bgtnsc05-news.ops.worldnet.att.net...
Is it doable to have a abstract class derived from a concrete class?
Yes.
Is it a good practice?
IMHO, no.
If so in what situation is this necessary?
Thanks in advance!
If you want a mix of concrete and abstract behavior you can start with the
abstract and then derive a base class with a partial implementation:
class Thing // abstract base class
{
public:
virtual const char *name() const = 0;
virtual do_something() = 0;
};
class Base : public Thing // partial implementation
{
private:
std::string m_name;
public:
Base(const char *i_name) : m_name(i_name) {}
virtual const char *name() const {return m_name.c_str();}
};
Now the client can derive from Base if he wants this implementation of
name() but can also derive from Thing if he wants to do it some other way.
If you derived Thing from a concrete type the concrete part would not be
negotiable.
--
Cy
http://home.rochester.rr.com/cyhome/
.
|
|
|
|
| User: "Gianni Mariani" |
|
| Title: Re: Abstract class derived from concrete class? |
04 Dec 2004 12:49:12 PM |
|
|
Wat wrote:
Is it doable to have a abstract class derived from a concrete class?
yes.
struct Fountation
{
int instance_number;
Fountation()
instance_number( next_number ++ )
{
}
static int next_number;
};
struct Interface
: virtual Fountation
{
virtual void ExplodeStuff() = 0;
};
....
Is it a good practice?
It depends on what you need it to do.
If so in what situation is this necessary?
Probably never although it might be the best way to implement somthing.
.
|
|
|
|

|
Related Articles |
|
|