473,908 Members | 3,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concrete class

What kind of classes is qualified as "concrete classes"?

When should a member function in a class defined as "pure virtual" and when
as "virtual"?

Thanks!
Jul 22 '05 #1
9 5895
On Sat, 01 May 2004 20:15:59 GMT, "mead" <ph******@light .com> wrote:
What kind of classes is qualified as "concrete classes"?
One you can instantiate. directly. In the ubiquitous "Shape" class
example, with a base class named "Shape" and then derived classes such
as "Circle", "Rectangle" , etc., it makes sense to say
Circle c;
but not
Shape s;

(Although
Shape *s
would make perfect sense, as long as you don't try to do:
Shape *s = new Shape;

When should a member function in a class defined as "pure virtual" and when
as "virtual"?
That's actually quite related to your first question. The way to make
a class be abstract is to give it at least one pure virtual function.
If a base class contains one or more pure virtual functions, there are
really two things going on. One is that the class is abstract; but for
that alone, a single pure virtual function would have been sufficient.
The other thing going on is that classes which derive from the base
class must implement /each/ of the pure virtual functions they inherit
in order to qualify as a concrete class. So if a derived class only
implements 7 out of 8 of the pure virtual functions it inherits, it is
still an abstract class. But a further derived class will inherit only
a single pure virtual function, and that further derived class would
become concrete by implementing that one function.
-leor

Thanks!


Jul 22 '05 #2
Leor Zolman <le**@bdsoft.co m> wrote in message
news:tf******** *************** *********@4ax.c om...
On Sat, 01 May 2004 20:15:59 GMT, "mead" <ph******@light .com> wrote:
What kind of classes is qualified as "concrete classes"?


One you can instantiate. directly. In the ubiquitous "Shape" class
example, with a base class named "Shape" and then derived classes such
as "Circle", "Rectangle" , etc., it makes sense to say
Circle c;
but not
Shape s;

(Although
Shape *s
would make perfect sense, as long as you don't try to do:
Shape *s = new Shape;
If "Shape" has a pure virtual function and this function is implemented in
Circle class as derived, then Circle becomes a class that can be
instantiate, thus Circle is concrete class but Shape isn't. Is it correct?

If Shape has no pure virtual function but virtual function(s), will it be a
concrete class?

When should a member function in a class defined as "pure virtual" and whenas "virtual"?


That's actually quite related to your first question. The way to make
a class be abstract is to give it at least one pure virtual function.
If a base class contains one or more pure virtual functions, there are
really two things going on. One is that the class is abstract; but for
that alone, a single pure virtual function would have been sufficient.
The other thing going on is that classes which derive from the base
class must implement /each/ of the pure virtual functions they inherit
in order to qualify as a concrete class. So if a derived class only
implements 7 out of 8 of the pure virtual functions it inherits, it is
still an abstract class. But a further derived class will inherit only
a single pure virtual function, and that further derived class would
become concrete by implementing that one function.
-leor


When defining a pure virtual function and when defining a virtual function
in a class?
Jul 22 '05 #3
"mead" <ph******@light .com> wrote...
Leor Zolman <le**@bdsoft.co m> wrote in message
news:tf******** *************** *********@4ax.c om...
On Sat, 01 May 2004 20:15:59 GMT, "mead" <ph******@light .com> wrote:
What kind of classes is qualified as "concrete classes"?
One you can instantiate. directly. In the ubiquitous "Shape" class
example, with a base class named "Shape" and then derived classes such
as "Circle", "Rectangle" , etc., it makes sense to say
Circle c;
but not
Shape s;

(Although
Shape *s
would make perfect sense, as long as you don't try to do:
Shape *s = new Shape;

If "Shape" has a pure virtual function and this function is implemented in
Circle class as derived, then Circle becomes a class that can be
instantiate, thus Circle is concrete class but Shape isn't. Is it

correct?

Yes.
If Shape has no pure virtual function but virtual function(s), will it be a concrete class?
The fact that virtual functions are all defined (not pure) basically
indicates that the class has specific behaviour. That usually means
that the class is concrete.
[..]
When defining a pure virtual function and when defining a virtual function
in a class?


I am not sure I understand the question (it's not a proper English
sentence), but, usually, you define a virtual function pure only if
it doesn't make sense (or is impossible) to specify any concrete
definition for it. Take the same Shape vs Circle example Leor gave
and try to declare/define the member function 'getArea'. I always
was a believer that doing it is much better way to understand than
listening to or reading an explanation.

Victor
Jul 22 '05 #4
On Sat, 01 May 2004 21:35:01 GMT, "mead" <ph******@light .com> wrote:
Leor Zolman <le**@bdsoft.co m> wrote in message
news:tf******* *************** **********@4ax. com...
On Sat, 01 May 2004 20:15:59 GMT, "mead" <ph******@light .com> wrote:
>What kind of classes is qualified as "concrete classes"?
One you can instantiate. directly. In the ubiquitous "Shape" class
example, with a base class named "Shape" and then derived classes such
as "Circle", "Rectangle" , etc., it makes sense to say
Circle c;
but not
Shape s;

(Although
Shape *s
would make perfect sense, as long as you don't try to do:
Shape *s = new Shape;
>If "Shape" has a pure virtual function and this function is implemented in
Circle class as derived, then Circle becomes a class that can be
instantiate, thus Circle is concrete class but Shape isn't. Is it correct?

Yes, assuming no (other) unimplemented pure virtuals in Circle.

If Shape has no pure virtual function but virtual function(s), will it be a
concrete class? Yes.

>When should a member function in a class defined as "pure virtual" andwhen >as "virtual"?
That's actually quite related to your first question. The way to make
a class be abstract is to give it at least one pure virtual function.
If a base class contains one or more pure virtual functions, there are
really two things going on. One is that the class is abstract; but for
that alone, a single pure virtual function would have been sufficient.
The other thing going on is that classes which derive from the base
class must implement /each/ of the pure virtual functions they inherit
in order to qualify as a concrete class. So if a derived class only
implements 7 out of 8 of the pure virtual functions it inherits, it is
still an abstract class. But a further derived class will inherit only
a single pure virtual function, and that further derived class would
become concrete by implementing that one function.
-leor


When defining a pure virtual function and when defining a virtual function
in a class?

Are you asking when is it appropriate to define a function as pure virtual
vs. just plain virtual? I was trying to answer that in what I said above.
The short version: make it pure virtual if you require a derived class to
implement it in order for that derived class to qualify as a concrete
class. Or, just make /something/ virtual (typically the destructor) if you
want a class to be abstract but not to require some derived class to
necessarily have to implement anything in particular.
-leor
If you have a more specific question, ask away...
-leor


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #5

"mead" <ph******@light .com> wrote in message
news:3A******** ***********@bgt nsc05-news.ops.worldn et.att.net...
What kind of classes is qualified as "concrete classes"?

When should a member function in a class defined as "pure virtual" and when as "virtual"?

Thanks!

Hi,
may i answer your question a little differently. its good practise to
program to an interface. by interface in c++ i mean an
abstract class with ALL pure virtual functions.
So imagine you have your example of Shape and Circle. If you use the
above philosophy then it means that your Shape is an interface. This is a
lil different philosophy and there will be some non takers
for this but as a thumb rule almost never have a class with pure virtual
function and some non pure virtual functions. So if there is a
class with a pure virtual function, then let it just have such as those. You
can imagine this to be an interface.
The benefit of doing this is to keep the inheritance hierarchy at a low
depths!!

kutty
Jul 22 '05 #6
Kutty Banerjee <ku****@wpi.edu > wrote in message
news:c7******** **@bigboote.WPI .EDU...

"mead" <ph******@light .com> wrote in message
news:3A******** ***********@bgt nsc05-news.ops.worldn et.att.net...
What kind of classes is qualified as "concrete classes"?

When should a member function in a class defined as "pure virtual" and when
as "virtual"?

Thanks!

Hi,
may i answer your question a little differently. its good practise to
program to an interface. by interface in c++ i mean an
abstract class with ALL pure virtual functions.
So imagine you have your example of Shape and Circle. If you use the
above philosophy then it means that your Shape is an interface. This is a
lil different philosophy and there will be some non takers
for this but as a thumb rule almost never have a class with pure virtual
function and some non pure virtual functions. So if there is a
class with a pure virtual function, then let it just have such as those.

You can imagine this to be an interface.
The benefit of doing this is to keep the inheritance hierarchy at a low depths!!

kutty

I like what you said about "program to an interface." However, "The benefit
of doing this is to keep the inheritance hierarchy at a low depths" is
confusing since adding an interface is always making inheritance hierarchy
deeper. Am I right on this?
Jul 22 '05 #7

"mead" <ph******@light .com> wrote in message
news:n3******** ************@bg tnsc04-news.ops.worldn et.att.net...
Kutty Banerjee <ku****@wpi.edu > wrote in message
news:c7******** **@bigboote.WPI .EDU...

"mead" <ph******@light .com> wrote in message
news:3A******** ***********@bgt nsc05-news.ops.worldn et.att.net...
What kind of classes is qualified as "concrete classes"?

When should a member function in a class defined as "pure virtual" and when
as "virtual"?

Thanks!

Hi,
may i answer your question a little differently. its good practise to program to an interface. by interface in c++ i mean an
abstract class with ALL pure virtual functions.
So imagine you have your example of Shape and Circle. If you use the above philosophy then it means that your Shape is an interface. This is a lil different philosophy and there will be some non takers
for this but as a thumb rule almost never have a class with pure virtual
function and some non pure virtual functions. So if there is a
class with a pure virtual function, then let it just have such as those.

You
can imagine this to be an interface.
The benefit of doing this is to keep the inheritance hierarchy at a

low
depths!!

kutty

I like what you said about "program to an interface." However, "The

benefit of doing this is to keep the inheritance hierarchy at a low depths" is
confusing since adding an interface is always making inheritance hierarchy
deeper. Am I right on this?

Hi,
Yes i was not clear on the part about keeping hierarchy depths low. Consider
the
following example.

Method One:
class A
method 1
method 2
method 3
//All virtual methods!!

Class B: public A
method 1
method 2
method 3
//All the above methods are different implementations than those of
//class A.

Class C:public B
method 1
method 2
method 3
method 4
method 5
So we have three level hierarchy here!! how to make this two level?
to begin with, class B should inherit from Class X where class X is
the interface of class A(exact same method signaturres but no body, so
abstract class)
There must be another interface Class Y with methods 4 and 5.
Class C now inherits from abstract classes X and Y ( im mixing abstract
class and interface intentionally)
and not from class B. If however Class C must have exactly the same
funcftionality for methods 1,2, 3
as those of class B then instead of inheriting from class B it could use
delegation. and if it doesnt ,
then completely forget about class B.

So finally we have class A inheriting from abstract class X and Class B
inheriting from abstract class X, Y.
If necessary it will delegate to Class B (meaning have composition of Class
B ). but in short we have two levels
of inheritance now.

kutty
Jul 22 '05 #8
>The benefit of doing this is to keep the inheritance hierarchy at a low
depths!

Why is this a benefit?

When is such a rule best applied?

Citing your example, what if there is a legitimate "isa" relationship between
class C and class B? Do you still support class C containing a B and
delegating to it and providing appropriate conversion operators so that the
substitutiabili ty of a C for a B is maintained?


Jul 22 '05 #9

"DaKoadMunk y" <da*********@ao l.com> wrote in message
news:20******** *************** ****@mb-m12.aol.com...
The benefit of doing this is to keep the inheritance hierarchy at a low depths!

Why is this a benefit?

When is such a rule best applied?

Citing your example, what if there is a legitimate "isa" relationship

between class C and class B? Do you still support class C containing a B and
delegating to it and providing appropriate conversion operators so that the substitutiabili ty of a C for a B is maintained?

Hi,
this is a contentious issue in the world of OO and is called inheritance vs
delegation (composition).
In fact if there is a genuine isa relation between c and b classes, thats
when delegation comes to the
rescue. The advantage of using delegation is as follows:

Ask your self the question why would C be isa B? Well maybe because B has
say 3 virtual (or may not be virtual)
that it uses as is (does not override) and in addition has 2 other methods
of its own. Rite? Now in this case since
C uses the same interface as B(refer to the initial eg i d given), therefore
it still has the 3 methods of B only that
inside each of these methods , it invokes a contained B objects
corresponding methods. with me so far?

Question is what is the advantage of doing this. wait, lets see the
disadvantages of this first!! You are increasing the
size of the object. Since you are delegating, therefore there is an extra
overhead involved, so purists could even
argue that it is making things slower . Correct!!

Advantage? Consider that instead of class B, there is a class D which has
hte same methods of B but implements
them differently. At runtime you want your class C to choose either the
implementation of B or D . Thats where
delegation comes to the rescue. Delegation gives you runtime flexibility
whereas inheritance gives you compile
time flexibility.

Last question? In the original example i have talked about inheriting from
interface (aka abstract class with only
pure virtual methods). So each class inherits from the interface. Isnt this
inheritance too? shouldnt we get rid of this
too? the answer is, try and differentiate between class inheritance and
interface inheritance. Interfae inheritance is
what i just mentioned. Class inheritance is what we got rid of .
Jul 22 '05 #10

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

Similar topics

2
2160
by: Wat | last post by:
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!
7
1696
by: Anitha | last post by:
What are abstract classes and concrete classes
4
1299
by: Julia | last post by:
Hi, I have a EmailMessage and a UrgentMessage objects both derived from IMessage i also have BadMedia and GoodMedia objects both derived from IMedia GoodMedia:IMedia string Subject string Body BadMedia:IMedia
3
1222
by: Julia | last post by:
Hi, In general my question is how can I set properties on a concrete class while programming against interfaces For example I have a MailServerFatory which can create two types of Mail servers and return IMailServer
8
2094
by: al pacino | last post by:
hi, i want to know how does c++ compiler prohibits the creation of instance of an abstract class? i think it must be checking on the vtable entry if there is an entry with zero(indicting abstract class) but exactly how it is done. thanks in advance
0
2849
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or...
3
2186
by: peter | last post by:
Hi, a "style" question. There is a method which creates a user in a database. I have to instantiate a user object, pass it to the method, and I get a completed user object back. public IUser Create(IUser user) { .... }
1
1702
by: Steve K. | last post by:
I added a property to an interface like this: <code> public interface ISimpleAddress { string CarrierFax{ get; set; } } </code>
1
5353
by: Stodge | last post by:
Yet another SWIG question (YASQ!). I'm having a problem with using an abstract base class. When generating the Python bindings, SWIG thinks that all the concrete classes that derive from this abstract class are abstract too and won't create the correct constructor. Abstract class: class CORE_API Shape
0
9876
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
11044
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10537
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8096
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7248
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5933
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6137
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4772
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3357
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.