473,395 Members | 1,622 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,395 software developers and data experts.

What does extending a class mean?

Hi, I read this in a book about the Xml classes in c#:

"These classes are abstract and therefore must be extended."

I just wanted to know what this statement means. I know it is not in
context, but the author gave it in such a matter that it appears
experience folks will know what it means to say a class is abstract and
extended.

Thanks.

Nov 17 '05 #1
5 2922
Basically, it means that you have to derive from the abstract base class
and implement functionality exposed by it (through abstract methods).

So if you had this:

public abstract class AbstractBase
{
// This needs to be implemented in any derived classes.
public abstract void DoSomething();
}

You need to do this:

public class Derived : AbstractBase
{
public override void DoSomething()
{
// Provide some implementation here.
}
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ne***********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi, I read this in a book about the Xml classes in c#:

"These classes are abstract and therefore must be extended."

I just wanted to know what this statement means. I know it is not in
context, but the author gave it in such a matter that it appears
experience folks will know what it means to say a class is abstract and
extended.

Thanks.

Nov 17 '05 #2
ne***********@gmail.com wrote:
Hi, I read this in a book about the Xml classes in c#:

"These classes are abstract and therefore must be extended."

I just wanted to know what this statement means. I know it is not in
context, but the author gave it in such a matter that it appears
experience folks will know what it means to say a class is abstract
and extended.

Thanks.


An abstract baseclass might contain some code (methods), but at least
has one "abstract" method. This is not a "real" method at all (it contains no
code), but rather some sort of "placeholder". By using an abstract method
you declare that all derived classes (classes that use this abstract class
as a baseclass) also have this method. If those derived classes are not
abstract themselves, they *must* provide code ("implement") these
abstract methods.

Why have methods that you can't use?
You can use that abstract type as a parameter type for some method
(this method might be in the same baseclass, or somewhere else).
When you call that method you have to specify some "real" object, that
derives from the (abstract) baseclass. Because the method (-signature)
is defined in that baseclass, the method (or rather compiler) knows it can
use it. How it is implemented is not important.

Hans Kesting
Nov 17 '05 #3
An abstract class is one that you can not create instances of. You need to
create a class that inherits from it (extends it) and then you create
instances of this derived class. Abstract classes are used when you want to
provide base functionality that you need to refine necessarily in derived
class. For example, you can have an abstract class Animal (you can not
create instances of it, since it is so generic or "abstract" ...) and you
derive classes extending it like Dog, Cat, etc, which are creatable classes.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

<ne***********@gmail.com> escribió en el mensaje
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi, I read this in a book about the Xml classes in c#:

"These classes are abstract and therefore must be extended."

I just wanted to know what this statement means. I know it is not in
context, but the author gave it in such a matter that it appears
experience folks will know what it means to say a class is abstract and
extended.

Thanks.

Nov 17 '05 #4
abstract classes are similar to Interfaces in that you can designate
signatures of methods, but different from interfaces in that you can
specifically implement functionality within an abstract class whereas
in an interface you are constrained to only having signatures of its
members.

interface ISomething
{
void DoSomething();
void DoSomethingElse();
}

abstract class Something
{
void DoSomething();
void DoSomethingElse()
{
// code here
}
}

Nov 17 '05 #5
I also forgot to actually answer your original question. But it appears
it has mostly been taken care of by others. Basically an abstract class
cannot be used by itself and must be inherited from by another class.

If a member of an abstract class is abstract itself:

abstract class Something
{
public abstract void DoSomething();
public void DoSomethingElse()
{
// code here
}
}

The inheriting class must override the abstract member of the abstract
class, but is not required to implement the non-abstract members.

public class MySomething : Something
{
public override void DoSomething()
{
// code here
}
}

Nov 17 '05 #6

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
9
by: Sasha | last post by:
Hi, I am extending standard IEnumerator, and I was just wondering what is the best way to make enumarator safe? What do I mean by safe? Detect deletes and all... My idea is to have private Guid...
3
by: Sathyaish | last post by:
I wanted to practice some Linked List stuff, so I set out to create a linked list. The plan was to create the following: (1) A linked list class in Visual Basic (2) A non-class based linked list...
7
by: A Traveler | last post by:
Hello all, i was just curious if anyone whos been playing with VS2005 could tell me... In javascript (and java??) you can alter the prototypes for an object in your project. I dont remember...
9
by: DrBonzo | last post by:
Is there any effective difference between doing something in the DragDrop event handler and doing it in the OnDragDrop(.) method of a control? I'm coming from a MFC background and am having a hard...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
16
by: chosechu | last post by:
Hello Pythoneers: I need to pass a list of named arguments to a function in a given order, and make sure these named arguments are retrieved using keys() in the same order they were given....
13
by: Ben Voigt | last post by:
Is there any way to have an overridden method which is not callable from the assembly overridding it? A contrived example (though I want this feature, my program has nothing to do with food...
8
by: Floortje | last post by:
Hi i have been struggeling with this question for quite some time now. I have some helper classes that handle images (upload an image, create thumbnails and show a imagelist), links (add link,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.