The Artima Developer Community
Sponsored Link

Agile Buzz Forum
OO Principles in .NET

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
OO Principles in .NET Posted: Jan 9, 2004 6:43 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: OO Principles in .NET
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From David Buck - Blog

Advertisement
It's interesting to see how many Smalltalk OO techniques aren't transferrable to .NET. I know that most techniques involving blocks won't work directly. There are a lot of small techniques, however, that aren't transferrable.

There are times when you need to test the class of an object. In Smalltalk, you would use one of three techniques:

  • isMemberOf:
  • isKindOf:
  • implement an isSomething method in Object (returning false) and in your class (returning true)
In .NET, you can use GetType() and compare the result to the typeof(MyClass) to do the same as isMemberOf:. The isKindOf: test isn't so easy. There's a method for types called IsSubclassOf which tests whether a class is a subclass of another. Sadly, it excludes the class itself, so to implement isKindOf:, you'd have to say:

   if ((object.GetType() == typeof(MyClass))
      || (object.GetType().IsSubclassOf(typeof(MyClass))))

Since you can't extend a system class (yet), there's no way to implement an InKindOf method in the proper class.

Now, consider the isSomething method approach. Since you can't implement a new method in Object, this technique has a limited usefulness.

How about conversion methods? Smalltalk's collections can convert themselves into other kinds using messages like asSet, asOrderedCollection, etc. Again, these methods don't exist in the .NET library and there's no way to add them.

I find the lack of extensions in .NET quite limiting. As I understand it, Microsoft is planning to add this feature. For now, we have to live with the limitations in the library.

Read: OO Principles in .NET

Topic: Breaking down the dialect barrier Previous Topic   Next Topic Topic: Smalltalk books online

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use