Methods as part of interfaces

  • Thread starter Thread starter RBrowning1958
  • Start date Start date
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
 
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.
 
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.
 
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
 
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
 
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
 
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
 
Back
Top