473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Abstract class derived from concrete class?

Wat
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!
Jul 22 '05 #1
2 2127
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.
Jul 22 '05 #2
"Wat" <we****@hotmail.com> wrote in message
news:%w*******************@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/
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Anitha | last post by:
What are abstract classes and concrete classes
9
by: Christian Christmann | last post by:
Hi, I've a class Handler which contains a STL list std::list<Abstract*> mAbstract; which is storing elements of the abstract class Abstract. Further this class has a getElement function to...
2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
3
by: Magne Ryholt | last post by:
I have a base class and a chain of derived classes. The base and its derived classes are all abstract except the last in chain (a concrete class). I want to provide some functionalities in the...
6
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
8
by: Manuel | last post by:
Hi! If I've a vector filled with abstract classes, can I push in it the derived classes too? Even if derived classes have new methods? I've done some experiments, and it seem I can push the...
7
by: tron.thomas | last post by:
Please consider the following code: class Abstract { public: virtual ~Abstract() {} virtual void Method() = 0; }; class Concrete : public virtual Abstract
7
by: ankitjain.bvcoe | last post by:
Hi i have the following problem in my design :::: i want to define an abstract class LogBuffer and derive two singleton classes from it i.e AlarmBuffer and FireWallBuffer.For this my design is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.