On 5/25/07, Christopher Frazier <[EMAIL PROTECTED]> wrote:
> Another short answer: classes aren't objects in .NET.

*Everything* is an object in .NET.

That's not true.

In .NET, a class is not an object. You can do typeof(), but what you
get back is a metadata structure which is not the class itself.

For example, if you want to call the static method "Foo" on the class
"Bar", in .NET, you have two choices:

1. Foo.Bar()
2. typeof(Foo).GetMethod("Bar", ...).Invoke()

What if you wanted to treat "Foo" in a way that you only cared about
having "a class which has the static method Bar() on it" without
knowing the class? In .NET, you only choice is reflection (#2), and I
think we can all admit that's not a very OO route.

In a language where classes are objects, like Ruby (the one I know
best), I can pass around the instance of the class object. So let's
say I write a method like this:

def MyMethod(obj)
   obj.Bar()
end

Now I can call MyMethod with the "Foo" class which has a static method
called Bar on it:

MyMethod(Foo)

Yes, that works. In fact, it doesn't really matter whether the method
is static, right? There's nothing in MyMethod that gives any
indication about Staticness. What if Bar() is an instance method on
the class Baz?

class Baz
   def Bar()
       ...
   end
end

Now I could pass an instance of Baz to MyMethod as well:

myBaz = Baz.new
MyMethod(myBaz)

That is what is meant when it's said that ".NET classes aren't
objects". You can't do this in .NET without using reflection, and even
if you use reflection, you have to differentiate between whether what
you have is an object (instance method, passing around a this point)
or a static method.

--
http://www.agileprogrammer.com/dotnetguy/
http://www.flickr.com/photos/dotnetguy/

(\__/)
(='.'=) This is Bunny. Copy and paste bunny into your
(")_(") signature to help him gain world domination.

===================================
This list is hosted by DevelopMentor�  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to