Friday, December 07, 2007
I'm doing a presentation on Dependence Injection at the December 12 meeting of ADNUG (Adelaide Dot Net Users Group). Here's my blurb:

The four main features of Object Oriented Programming - Inheritance, Abstraction, Encapsulation and Polymorphism - allow us to create applications where each class is nicely designed, easily tested, maintained and hence reusable across many projects. However, more often than not, the classes in our applications become tightly coupled and tangled with interdependencies, which in turn makes them difficult to test, maintain and reuse. Our applications become fragile and we lose much of the benefit of Object Oriented Programming.

The Dependency Injection Pattern (otherwise known as Inversion of Control) maintains louse coupling of the classes that depend on each other in our applications by "injecting" the dependencies at run-time rather than design-time. In .Net Dependency Injection makes great use of interfaces, thus promoting "Interface Driven Development" and/or "Test Driven Development", and facilitates many other Design Patterns such as Model-View-Controller, Model-View-Presenter, Factory Patterns, the Strategy Pattern, etc.

There are numerous Dependency Injection frameworks available for .Net – Castle MicroKernel/Windsor, Patterns & Practices ObjectBuilder, PicoContainer.NET, Puzzle.NFactory, Spring.NET, StructureMap, Ninject – but I’ve written my own. J

In this presentation, I'm going to demonstrate a couple of aspects of my Dependency Injection framework. There is far more in the total framework than can be discussed in 45 minutes, so I shall be cover the basics of "Interface Driven Development" and the use of "Abstract Factories" my framework to show how I can keep my classes loosely coupled and testable.

I'm going to aim to keep the presentation focused on the practical application of my framework, but there are some very funky "über"-cool coding techniques under-the-hood that would be great to discuss. So for those of you wanting to discuss the implementation of the framework in more detail I'm happy to do so after the presentation. (You can tell I'm proud of my creation, right?)

posted on Friday, December 07, 2007 9:07:23 AM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [3] Trackback
 Monday, November 19, 2007

My new HTC Touch ran out of memory on the weekend and was forced to do hard reset.

I did a couple of soft resets first, and the Touch gave me a couple of nice dialog boxes politely asking me to delete some files, but then it froze before I could actually delete the files.

So a big warning for Touch users. Don't let your HTC Touch run out of memory.
posted on Monday, November 19, 2007 11:10:12 AM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [0] Trackback
 Wednesday, June 20, 2007

I got my hands on the new iRiver T60 MP3 player today.

It's pretty good.

I've only found a few issues that I would like to resolve, but it works very well for my podcast listening needs.

It'll resume from where it was turned off, it allows for copying of files to a USB Mass Storage drive, it will play the podcasts in the order that they are saved to the device.

The only two downsides so far is that setting the "Playback Speed" option to the fastest setting makes podcasts sound like I'm listening to the chipmonks, and every action seems to require the first button click to "wake up" the device and I need to then press the button again to make it do what I wanted. I can live with these issues.

posted on Wednesday, June 20, 2007 7:48:53 PM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [2] Trackback
 Monday, June 18, 2007

I’ve got Windows Vista Ultimate

It came with my Dell Laptop

Now, in the last month or so, weird things are happening. Quicken decided to crash on me every time I run it. Anytime I click on a link in any program I get a dialog box telling me the link didn’t work, but then Firefox pops up and all is well. And now…

Media Center has just gone and disappeared from my system. I just can’t find it. I didn’t uninstall. It’s just not there.

Weird.

I’m about two months in since getting the computer. I’d hope to go at least 6 months before a repave. Maybe it’s time to start again.

Sheesh.

It’s not the “Wow” I was looking for.

posted on Monday, June 18, 2007 9:01:57 PM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [0] Trackback
 Saturday, June 16, 2007

It's taken a while, but I've finally got a version of dasBlog that will stop comment spam.

I've set up a new install and I've imported my old content – so I'm now spam free I hope.

posted on Saturday, June 16, 2007 3:26:30 PM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [1] Trackback
 Tuesday, November 15, 2005

The recently signed Australia-US Free Trade Agreement forces both countries to enact certain laws.

One such is regarding copyright protection technologies. Australia is debating the "modding" of game consoles. Read on:

http://australianit.news.com.au/articles/0,7204,17239019%5e16123%5e%5enbv%5e,00.html
posted on Tuesday, November 15, 2005 9:52:35 AM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [0] Trackback
 Thursday, November 10, 2005

I'm finding the whole copyright thing on the web more and more hilarious everyday.

Read this - http://www.lessig.org/blog/archives/003202.shtml - and enjoy!

posted on Thursday, November 10, 2005 12:40:05 PM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [0] Trackback
 Thursday, June 09, 2005

I've recently been wondering why Microsoft, in their infinite wisdom, has decided to provide helper code in both C# & VB.Net that promotes bad OOP coding.

Have you ever implemented an interface in either language?

Well, Visual Studio - in 2002, 2003 & Whidbey - auto-creates the implementation signatures in both languages and marks them "Public". I'm sure you know that.

Now this is a big problem in both C# & VB.Net. Let's see why in C# first.

If I write this code:

      class Module
      {

            [STAThread]
            static void Main(string[] args)
            {
                  ClassY InstanceY = new ClassY();
                  ((IFoo)InstanceY).DoMethod();
                  ((IBar)InstanceY).DoMethod();
                  InstanceY.DoMethod();
                  Console.ReadLine();
            }
      }
 
      public interface IFoo {void DoMethod();}
      public interface IBar {void DoMethod();}
 
      public class ClassX : IFoo   
      {
            public void DoMethod() {Console.WriteLine("IFoo.DoMethod");}
      }
 
      public class ClassY : ClassX, IBar
      {
            public void DoMethod() {Console.WriteLine("IBar.DoMethod");}
      }

Visual Studio complains with "The keyword new is required on 'ConsoleApplicationCSharp.ClassY.DoMethod()' because it hides inherited member 'ConsoleApplicationCSharp.ClassX.DoMethod()'".

So I insert "new" on "DoMethod()" in "ClassY", like this:

      public class ClassY : ClassX, IBar
      {
            public new void DoMethod() {Console.WriteLine("IBar.DoMethod");}
      }

My output becomes:

IFoo.DoMethod
IBar.DoMethod
IBar.DoMethod

Pretty much what I should expect, but I'm a conscientious programmer so I want to avoid "new" (or "shadows" in VB.Net) so I mark the "ClassY" method as "private" rather than "public", like so:

      public class ClassY : ClassX, IBar
      {
            private new void DoMethod() {Console.WriteLine("IBar.DoMethod");}
      }

The output now becomes:

IFoo.DoMethod
IFoo.DoMethod
IFoo.DoMethod

When I explicitly call the "IBar" interface method it calls the method of the class that doesn't even implement the interface. That's crazy!

So, to avoid the problem I declare the implementation explicitly:

      public class ClassX : IFoo   
      {
            void IFoo.DoMethod() {Console.WriteLine("IFoo.DoMethod");}
      }
 
      public class ClassY : ClassX, IBar
      {
            void IBar.DoMethod() {Console.WriteLine("IBar.DoMethod");}
      }

Now, of course, the code that calls the "DoMethod()" on the native "InstanceY" object can't see either method. But isn't that what we really would want to do? It avoids any ambiguity.

Let's look at a similar thing in VB.Net. My code is now this:

    Module Main
        Sub Main()
            Dim InstanceY As New ClassY
            CType(InstanceY, IBar).DoBar()
            CType(InstanceY, IFoo).DoFoo()
            InstanceY.DoBar()
            InstanceY.DoFoo()
            Console.ReadLine()
        End Sub
    End Module
 
    Public Interface IFoo
        Sub DoFoo()
    End Interface
 
    Public Interface IBar
        Sub DoBar()
    End Interface
 
    Public Class ClassX
        Implements IFoo
        Public Sub DoBar() Implements IFoo.DoFoo
            Console.WriteLine("IFoo.DoFoo")
        End Sub
    End Class
 
    Public Class ClassY
        Inherits ClassX
        Implements IBar
        Public Sub DoFoo() Implements IBar.DoBar
            Console.WriteLine("IBar.DoBar")
        End Sub
    End Class

Notice that since I'm being a nasty programmer I've swapped the Names of the method implementations. Think of it like replacing "Save" with "Delete".

Now of course, what happens? My dear user runs this code and gets the following:

IFoo.DoFoo
IBar.DoBar
IBar.DoBar
IFoo.DoFoo

Again, the answer is to explicitly declare both implementations "Private". It avoids any ambiguity.

But the answer is not to enforce the use of "Private". Apart from the times when "Protected" is needed, there may well be a need for the developer to make an implementation of an interface "Public" or "Friend".

So, my open question, why has Microsoft made "Public" the default for implementation of interfaces?

posted on Thursday, June 09, 2005 7:21:00 PM (Cen. Australia Standard Time, UTC+09:30)  #    Comments [0] Trackback