473,396 Members | 1,933 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.

Methods as part of interfaces

Hello,

Here's a question - when reading through a class's code and seeing
method implementations - how do you know whether a method is
implementing something from an interface or is just a method in the
class and has nothing to do with interface. Do you need to look up the
entire inheritance hierarchy to see if a class implements an interface
which defines the method? A form's dispose comes to mind....

Ta

Ray

Nov 5 '07 #1
6 995
Ray,

Well, the easy thing to do here would be to look at the class definition
itself. If the class implements an interface, you have to declare it in the
class definition.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<RB***********@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
Hello,

Here's a question - when reading through a class's code and seeing
method implementations - how do you know whether a method is
implementing something from an interface or is just a method in the
class and has nothing to do with interface. Do you need to look up the
entire inheritance hierarchy to see if a class implements an interface
which defines the method? A form's dispose comes to mind....

Ta

Ray

Nov 5 '07 #2
On Nov 5, 1:37 pm, RBrowning1...@gmail.com wrote:
Hello,

Here's a question - when reading through a class's code and seeing
method implementations - how do you know whether a method is
implementing something from an interface or is just a method in the
class and has nothing to do with interface. Do you need to look up the
entire inheritance hierarchy to see if a class implements an interface
which defines the method? A form's dispose comes to mind....

Ta

Ray
I have had this question myself. There really isn't a better way than
going through and seeing whether the interface has such a method. You
can make the task easier with the class explorer.

However, in most scenarios, it is more important to know if a class
implements an interface rather than knowing if one of its methods
belongs to an interface. How should I put that? During refactoring, it
is nice to know whether you can take things away from a class without
ruining a heirarchy. In this case, you are kind of stuck looking
through all the interfaces or you can change the method name and see
if it will change the interface's name (which it will prompt you
about). . . . assuming you are working in Visual Studio.

It will get the job done.

Nov 5 '07 #3
On Nov 5, 9:00 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Ray,

Well, the easy thing to do here would be to look at the class definition
itself. If the class implements an interface, you have to declare it in the
class definition.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

<RBrowning1...@gmail.comwrote in message

news:11**********************@57g2000hsv.googlegro ups.com...
Hello,
Here's a question - when reading through a class's code and seeing
method implementations - how do you know whether a method is
implementing something from an interface or is just a method in the
class and has nothing to do with interface. Do you need to look up the
entire inheritance hierarchy to see if a class implements an interface
which defines the method? A form's dispose comes to mind....
Ta
Ray- Hide quoted text -

- Show quoted text -
Nicholas,

That's clear - but if the interface is declared way up the class
hierarchy....

Ray

Nov 6 '07 #4
Are you trying to do this programatically, or are you trying to
determine this simply by eyeing code?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<RB***********@gmail.comwrote in message
news:11*********************@o80g2000hse.googlegro ups.com...
On Nov 5, 9:00 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Ray,

Well, the easy thing to do here would be to look at the class
definition
itself. If the class implements an interface, you have to declare it in
the
class definition.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

<RBrowning1...@gmail.comwrote in message

news:11**********************@57g2000hsv.googlegr oups.com...
Hello,
Here's a question - when reading through a class's code and seeing
method implementations - how do you know whether a method is
implementing something from an interface or is just a method in the
class and has nothing to do with interface. Do you need to look up the
entire inheritance hierarchy to see if a class implements an interface
which defines the method? A form's dispose comes to mind....
Ta
Ray- Hide quoted text -

- Show quoted text -

Nicholas,

That's clear - but if the interface is declared way up the class
hierarchy....

Ray

Nov 6 '07 #5
On Nov 6, 3:42 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Are you trying to do this programatically, or are you trying to
determine this simply by eyeing code?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

<RBrowning1...@gmail.comwrote in message

news:11*********************@o80g2000hse.googlegro ups.com...
On Nov 5, 9:00 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Ray,
Well, the easy thing to do here would be to look at the class
definition
itself. If the class implements an interface, you have to declare it in
the
class definition.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
<RBrowning1...@gmail.comwrote in message
>news:11**********************@57g2000hsv.googlegr oups.com...
Hello,
Here's a question - when reading through a class's code and seeing
method implementations - how do you know whether a method is
implementing something from an interface or is just a method in the
class and has nothing to do with interface. Do you need to look up the
entire inheritance hierarchy to see if a class implements an interface
which defines the method? A form's dispose comes to mind....
Ta
Ray- Hide quoted text -
- Show quoted text -
Nicholas,
That's clear - but if the interface is declared way up the class
hierarchy....
Ray- Hide quoted text -

- Show quoted text -
Just by eying the code...

Ray

Nov 6 '07 #6
You could always look in the Class Browser in VS.NET (assuming you are
using that). It should be able to quickly show you the inheritance heiarchy
(minus the methods, or at least, collapsed) and the interfaces it
implements.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<RB***********@gmail.comwrote in message
news:11**********************@z9g2000hsf.googlegro ups.com...
On Nov 6, 3:42 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
> Are you trying to do this programatically, or are you trying to
determine this simply by eyeing code?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

<RBrowning1...@gmail.comwrote in message

news:11*********************@o80g2000hse.googlegr oups.com...
On Nov 5, 9:00 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Ray,
> Well, the easy thing to do here would be to look at the class
definition
itself. If the class implements an interface, you have to declare it
in
the
class definition.
>--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
><RBrowning1...@gmail.comwrote in message
>>news:11**********************@57g2000hsv.googleg roups.com...
Hello,
Here's a question - when reading through a class's code and seeing
method implementations - how do you know whether a method is
implementing something from an interface or is just a method in the
class and has nothing to do with interface. Do you need to look up
the
entire inheritance hierarchy to see if a class implements an
interface
which defines the method? A form's dispose comes to mind....
Ta
Ray- Hide quoted text -
>- Show quoted text -
Nicholas,
That's clear - but if the interface is declared way up the class
hierarchy....
Ray- Hide quoted text -

- Show quoted text -

Just by eying the code...

Ray

Nov 6 '07 #7

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

Similar topics

15
by: beliavsky | last post by:
What are the pros and cons of defining a method of a class versus defining a function that takes an instance of the class as an argument? In the example below, is it better to be able to write...
8
by: Just D | last post by:
All, What are advantages and disadvantages of these two different approaches? 1 . I create a base class with a few virtual methods, then I derive my classes from this class, override these...
7
by: mdc | last post by:
Hi, Is there any way to implement an interface as a static method in C#? If not, is this a bug? Micheal.
8
by: Steven Livingstone | last post by:
Anyone able to explain to me why you cannot define an interface that can then be implemented using static methods? I understand the C# CLS states this, but just interested in the reasons behind...
17
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component...
4
by: John C | last post by:
I'm new to C#, so just point me at the correct reference material if this question has been answered before. When creating a new class which implements the IDictionary interface, two versions of...
4
by: don | last post by:
I have two existing interfaces having methods with same names. Now I have to implement both intrfaces in one class. Is there any way I could implement methods with same names in both interfaces...
2
by: fgh.vbn.rty | last post by:
Hi, I'm not sure if i'm asking the question correctly but anyway here it is. Say I have 3 classes - class A, class B, class R. 1) A and B are the building blocks and R is like a repository...
3
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...

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.