Microsoft Open Door 2010 – Day 1

Last week I had the chance to witness Microsoft Open Door 2010 held at Sheraton Hotel, Karachi on Nov 4 and 5. The event was aimed at showcasing the latest as well the upcoming Microsoft products in the market.

The event had sessions carried out in parallel tracks. I chose to attend those in the developer track mostly. The precise list of the sessions is available at Microsoft official site.

The first and the most interesting one of those I attended was by Asli Bilgin(Web Strategy Lead for Middle East & Africa). She shared some interesting facts about the developer community in Pakistan, comparing it to Turkey(her birthplace).

  • Geographical Area – Pakistan 790 sq km, Turkey 780 sq km
  • Population – Pakistan 170 M, Turkey  72 M
  • Web developers – Pakistan 20%, Turkey 10% of Total MEA (Middle East & Africa) web developers.
  • Market Share in Web Hosting : Pakistan 4%, Turkey 35%
  • No. of registered User Groups : Pakistan 41, Turkey 9, South Africa 9, Egypt 0, Saudi Arabia 9

That’s encouraging!

Apart from the facts, here are a couple of things that caught my attention:

  • Microsoft WebMatrix – a free Microsoft tool that provides rapid development methodologies for building websites on Windows. It includes IIS Express (a development Web server), ASP.NET (a Web framework), and SQL Server Compact (an embedded database).
  • Micorosoft Web Platform Installer – another free Microsoft tool that facilitates setting up your environment for web development on Windows.

InshaAllah, I plan to share further about these in later posts. More stuff about Microsoft Open Door 2010(Day 2) in my next post.

Advertisements

, , , , , ,

3 Comments

Multiple Inheritance with Strategy Pattern

When I was introduced to programming languages like Java and C# (coming from C++), one of the things that I really missed was Multiple Inheritance. That is, in these languages we could not say something like:

class AllRounder : Batsman, Bowler { }

These languages offer interfaces to establish polymorphism. That is we can say (in C#):

class Batsman
{
     void Bat()
     {  Console.WriteLine("Do batting.");  }
}
interface IBowler
{
     void Bowl();
}
class Bowler : IBowler
{
     public void Bowl()
     {  Console.WriteLine("Do bowling.");  }
}
class AllRounder : Batsman, IBowler
{
     public void Bowl()
     {  Console.WriteLine("Do bowling.");  }
}

Do you see a problem here…? I do.

The problem is that the Bowl() is implemented twice, although the code it contains is by definition the same. Its a shame calling this code ‘Multiple inheritance’ because actually interfaces do not inherit anything. They just ensure a contract. The only feature of inheritance that interface provide is Polymorphism. You can say:

IBowler bowler = new AllRounder();
bowler.Bowl();

But the problem with duplication is that if we need changing Bowl() in the Bowler class we will almost always require changing the Bowl() implementation in the AllRounder class. The are a few ways to get around this. The key to all solutions I can think of at the moment is to introduce a layer of abstraction i.e. wrap the code of Bowl() into code commonly accessible to both. I’ll choose using the Strategy Pattern

interface IBowlingBehavior
{
    void PerformBowling();
}
interface IBowler
{
    IBowlingBehavior BowlingBehavior { get; set; }
    void Bowl();
}
class Batsman
{
    void Bat()
    {  Console.WriteLine("Do batting.");  }
}
class Bowler : IBowler
{
    public IBowlingBehavior BowlingBehavior { get; set; }
    public void Bowl()
    {  BowlingBehavior.PerformBowling();  }
}
class AllRounder : Batsman, IBowler
{
    public IBowlingBehavior BowlingBehavior { get; set; }
    public void Bowl()
    {  BowlingBehavior.PerformBowling(); }
}
class DefaultBowlingBehavior : IBowlingBehavior
{
    public void PerformBowling()
    {  Console.WriteLine("Do bowling.");  }
}

This allows us to implement the bowling code in one place as well as select one of the many implementations of BowlingBehaviors at runtime!

class SpinBowlingBehavior : IBowlingBehavior
{
    public void PerformBowling()
    {  Console.WriteLine("Do spin bowling.");  }
}
class FastBowlingBehavior : IBowlingBehavior
{
    public void PerformBowling()
    {  Console.WriteLine("Do fast bowling.");  }
}

and later we can say…

Bowler fastBowler = new Bowler { BowlingBehavior = new FastBowlingBehavior() };
fastBowler.Bowl(); //Bowl Fast
fastBowler.Bowl(); //Bowl Fast
fastBowler.BowlingBehavior = new SpinBowlingBehavior();
fastBowler.Bowl(); //Bowl Slow, fool the batsman

, , , ,

2 Comments