473,395 Members | 1,941 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.

Abstract class must implement interfaces?

Hi,

Why must abstract classes implements all the methods/property in the
interface it implements? Since it's an abstract class it shouldn't be able
to be instantiated and the child classes are those that should implement the
interface. However in .Net I have to implement the interface in the abstract
class as well.

Why is this so?

Thanks
Jul 21 '05 #1
4 2429
Why must abstract classes implements all the methods/property in the
interface it implements?


They don't, really. They just have to declare the method, not
necessarily provide an implementation. So the following works

interface IFoo
{
void Bar();
}

abstract class FooBaseImpl : IFoo
{
public abstract void Bar();
}

class ConcreteFoo : FooBaseImpl
{
public override void Bar() {}
}

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
> >Why must abstract classes implements all the methods/property in the
interface it implements?
They don't, really. They just have to declare the method, not
necessarily provide an implementation. So the following works


Yes correct, however why do they even need to declare the methods? Since
they are not defining the methods. It should be left to the concrete class
to implement those methods. Isn't this actually logical? What is the reason
that it is implemented that way?

Thanks,

interface IFoo
{
void Bar();
}

abstract class FooBaseImpl : IFoo
{
public abstract void Bar();
}

class ConcreteFoo : FooBaseImpl
{
public override void Bar() {}
}

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jul 21 '05 #3
"wesley" <we*@inthemix.com.au> schrieb

dim i as IFoo
dim o as FooBaseImpl

i = o

This wouldn't work if FooBaseImpl didn't implement the interface.

--
Armin
Why must abstract classes implements all the methods/property in
the interface it implements?


They don't, really. They just have to declare the method, not
necessarily provide an implementation. So the following works


Yes correct, however why do they even need to declare the methods?
Since they are not defining the methods. It should be left to the
concrete class to implement those methods. Isn't this actually
logical? What is the reason that it is implemented that way?

Thanks,

interface IFoo
{
void Bar();
}

abstract class FooBaseImpl : IFoo
{
public abstract void Bar();
}

class ConcreteFoo : FooBaseImpl
{
public override void Bar() {}
}


Jul 21 '05 #4
> dim i as IFoo
dim o as FooBaseImpl

i = o

This wouldn't work if FooBaseImpl didn't implement the interface.
Why wouldn't it work? Because if FooBaseImpl is abstract then there is no
need to implement the interface methods? Because it may not be relevant to
implement it there. If FooBaseImpl is abstract and declared that it
implements the IFoo interface the compiler should just leave it be and only
bind the methods at runtime and it doesn't need to check it at compiler
time. IMO

wes
--
Armin
>Why must abstract classes implements all the methods/property in
> the interface it implements?

They don't, really. They just have to declare the method, not
necessarily provide an implementation. So the following works


Yes correct, however why do they even need to declare the methods?
Since they are not defining the methods. It should be left to the
concrete class to implement those methods. Isn't this actually
logical? What is the reason that it is implemented that way?

Thanks,

interface IFoo
{
void Bar();
}

abstract class FooBaseImpl : IFoo
{
public abstract void Bar();
}

class ConcreteFoo : FooBaseImpl
{
public override void Bar() {}
}

Jul 21 '05 #5

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

Similar topics

15
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that...
8
by: Vishal Gandhi | last post by:
Hi , Please help me by advising an real life scenario where Abstract Classes should be used over Interfaces or vice versa . Whats the basic difference between Abstract Class and interface other...
5
by: Michael McCarthy | last post by:
I want to develop plugin support for a system.montitor module I am working on. A lot of the modules will do mostly interop stuff for an older system, but I want to use it myself as well to monitor...
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
18
by: Bradley | last post by:
I'm trying to determine if there's a general rule for when an Interface should used vs. an Abstract Class. Is there any design advantage to using one or the other? Brad
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
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
5
by: Tony Johansson | last post by:
Hello! Here I have an Interface called ITest and a class called MyClass which derive this intrface. As you can see I don't implement this method myTest in class MyClass because i use the...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.