Methods as part of interfaces

R

RBrowning1958

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
J

jehugaleahsa

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.
 
R

RBrowning1958

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]
- (e-mail address removed)




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....

Ray- Hide quoted text -

- Show quoted text -

Nicholas,

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

Ray
 
N

Nicholas Paldino [.NET/C# MVP]

Are you trying to do this programatically, or are you trying to
determine this simply by eyeing code?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

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]
- (e-mail address removed)




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....

Ray- Hide quoted text -

- Show quoted text -

Nicholas,

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

Ray
 
R

RBrowning1958

Are you trying to do this programatically, or are you trying to
determine this simply by eyeing code?

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




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]
- (e-mail address removed)

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
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

Are you trying to do this programatically, or are you trying to
determine this simply by eyeing code?

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




On Nov 5, 9:00 pm, "Nicholas Paldino [.NET/C# MVP]"
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.
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....

Ray- Hide quoted text -
- Show quoted text -

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top