Monthly Archives: October 2006

How to do multiple inheritance in C# – Implementation over delegation (IOD)

IOD is a very simple coding techniques which allows a developers fast implementation of an system interfaces and *multiple inheritance* in C# (I know:It is not supported :))

Well the whole idea is basically to have a class field of desired type and to expose functionality public properties of the class based on hidden calls to the member field

So if we have something like Class A and Class B are parents of a Class C.An example of that situation could be the case when we would have a user control which should be able to handle and present a list of customers

Illustration 1. UML Multiple inheritance diagram

Multiple inheritance in C# problem  ilustration

Because user control and List<T> are bot classes you couldn’t do that directly, by inheriting, because there is no support for multiple inheritance in the case of c# (and I’m happy with that because I think multiple inheritance when not properly used very often leads to class explosion anti pattern)

Usually developers are going to solution like this one which I think is bad solution:

Illustration 2. Inherit the inherited one anti pattern


Our collection class would inherit user control and our own user control would inherit that *power collection class*.
Even if it will do the task of multiple inheritance in C# I don’t like this solution because of the next facts:

a) Class B “the power collection” is now collection class with attributes of user controls, which is bed because all user control members are visible on collection level . What should developer of class c think about collection class which exposes width and height?

b)Class A could define some virtual members which could be overridden by class B

c)Class B couldn’t be reusable in case when somebody wants to use her primarily functionality (it is a collection) but don’t need the burden of a user control

d) It is very tightly coupled model.

e)It makes almost impossible inheritance of more than two parent classes

Code example


class CustomerCollection : System.Windows.Forms.UserControl


      protected virtual void Add(string customerName)


            /*Customer collection add method specific code*/


      protected virtual void Delete(string customerName)


            /*Customer collection delete method specific code*/




class MyUserControl: CustomerCollection


      /*MyUserControl specific code goes here*/


The right approach is by my opining implementation over delegation (IOD) approach which would in our case look like:

Illustration 3. Implementation over delegation multiple inheritance pattern

Implementation over delegation multiple inheritance pattern

This pattern is based on a fact that we define an interface of a class B and  than our class c is inheriting Class A directly (MyUserControl should inherit UserControl) and implements a IClassB interface.

The implementation of an interface itself is been done by keeping private member of a class B type and inside of the interface implementation methods we are just calling the method of that privately contained member.

interface ICustomerCollection


      void Add(string customerName);

      void Delete(string customerName);


class CustomerCollection : ICustomerCollection


      public void Add(string customerName)


            /*Customer collection add method specific code*/


      public void Delete(string customerName)


            /*Customer collection delete method specific code*/




class MyUserControl: UserControl, ICustomerCollection


      CustomerCollection _customerCollection=new CustomerCollection();


      public void Add(string customerName)




      public void Delete(string customerName)






Nero is working on Vista RC2 – Finally!

Although there are a lot of good free programs for burning CD/DVS’s and the Vista is supporting natively on OS level, it was really nice for me to discover that Nero had published Premium Reloaded version which supports Windows Vista as well

Nero 7 works on Windows Vista RC2

Download Nero Premium Reloaded Link


Technorati tags: , , , ,

How to blog with Microsoft Live Writer

Even blog server has a great WYSIWYG Microsoft, the best tool for posting is by my opinion Microsoft Live Writer, because it is a kind of smart client application which removes from you limitation of web world but also removes a need for copy & paste and the need for manual upload of pictures.

It is a one tool from upcoming Microsoft kitchen and it can be downloaded from Official live writer team blog address along with bunch a cool plug ins.

After download (~ x100Kb) is finished just install it and start it

As soon you try to create new post you would be presented next simple wizard to fill with blog provider data:

Step 1. Chose blog type (in case of blog server based blog chose another)

Choose blog type

Step 2. Setting your home page data

Step 3. Live Writer is analyzing your blog provider type

Step 4. Setting up the blog provider type

Step 5. setting the posting address (note that the highlighted text is only to be changed)


Step 6. Live writer is downloading blog style definition from blog server

Step 7. Setting up of Live Writer – Done!


Writing options

On the right there is a side bar with two important parts: Open/new part and insertation part

So when you click on Insert tags you are getting the dialog box for entering tags for the tag provider

You can set also blog server tag by clicking on the right top corner and choosing desired categories

After writing and tagging of your text has been done you can publish finished post by simply click on the publish button without any updating of the data

In case you would like to load & edit some already existing posting on your blog provider server just click on the Open button and you would be presented next screen


Technorati tags: , , ,

How to blog from Microsoft Word 2007


This posting I’m writing by using Microsoft Word publish to blog new and excellent feature. That’s how you are having the usual toolbar like the one you were using writing other word documents, on the fly spell checker, advanced possibilities to format look & feel of the text etc..

Illustration 1. Word ribbon blog post toolbar pad

Illustration 2. Word ribbon Insert toolbar pad


How to start making it ?

Very easy! There are two different ways:


Illustration 3. Converting of your already existing document by publishing it

Illustration 4. Creating blog post as a new document


Setting up blog provider (community server)

In both cases, in case you haven’t done it already you would be presented blog provider setup wizard which is fairly simple and straight forward so I’ll just put screen shoots to explain them

Step 1. Welcome screen

Step 2. Choose your blog provider type

(My blog provider is based on Community Server but more details about setting up other blog providers can be found on Office 2007 Blog Provider help section)

Step 3. Setting up CS provider details

(NOTE: path is something like <a href="http://%3cyourhostname%3e/blogs/metablog.ashx&quot; mce_href="http:///blogs/metablog.ashx”>http://<yourhostname>/blogs/metablog.ashx)

Step 4. Setting up picture options

(In Beta 2 you have to set up your FTP account data because CS is not supporting auto upload of pictures. Upload URL is the FTP path where the pictures should be stored and the SourceUrl is the http address where from the pictures should be loaded when browser request them)

Step 5. After that blog provider is been contacted

Step 6. And in case you have done it well, there is a Congratulations screen

And after that setting up the blog provider when you have done your blog post, publishing it is also pretty trivial:

Click on Publish button on ribbon

(In case you would like to publish only a draft click on a menu arrow beneath the publish icon)

You’ll be asked to provide your FTP account data

And then FTP transfer would start


But, there are some problems with it such as the one when the pictures uploaded are bloated to 200-300K even original one inserted in word were 20-30K. Then styles are not possible to be downloaded so Word is not rendering the post like it would look on the web

Summarized: very promissing tecnology for us bloggers but untill some *more final* version I’ll stick to my Microsoft Live Writter

Technorati tags: , ,

Navigation wizard IE 7 style



One of the coolest new things (at least for me) in IE 7 and Vista upcoming wave is redesigned minimalist wizard navigation interface.

Instead of *old style* wizards with a bunch of the navigation buttons at the bottom like the wizard shown below

Illustration 1. Classic windows wizard screen 


IE 7 and Windows Vista are introducing the new cool navigator control which fully replaces the functionality of the old one. It looks like a plain two arrows (left and right with a drop down menu)

Something like this in

Illustration 2. Internet Explorer 7 version navigation controls

or in case of Windows Vista

Illustration 3. Windows Vista version navigation controls


The whole original wizard toolbar is therefore replaced with small and nice self explanatory looking interface:

back and next are obviously left and right arrow if a user would wanted to give up, he could do that by closing the IE 7 window or windows explorer window As you can see, the same approach is implemented in web and windows world, which makes additional positive effect to user experience. Wizard navigation therefore stops to be predominant on the wizard and starts to be supportive from second plan and allowing implementation of wizard navigation logic applicable on waste range of cases.

This new navigational functionality could be easily made by using Windows Presentation Foundation (WPF) because when you set Application.StartupUri to either a XAMl or HTML page, Application (knowing that neither of these can provide its own window) creates an instance of NavigationWindow to host them and Navigation Windows derives from Window and extends its visual appearance to look like a browser by adding navigation items: left and right arrow and drop down menu

Because it is fairly trivial to implement and I’ll need that navigation functionality to use in next article of Smart Client Factory series , I’ve decided to post a blog about building it (off course just on very general way)

UI concept

UI part of the control would be based separation of the navigation control to three parts: back navigation button

part, forward navigation button part and menu drop down part.

Illustration 4. Regions of IE7Navigator control

IE7 Navigator control schema

The control would be covered with a background picture box which would show the control in initial *disabled all* state.

Illustration 5. Disabled background shown only

 Disabled look of the control

On top of that background picture there would be three picture box controls which would cover each of the three parts and show appropriate images for mouse hover and click events, as shown on next illustrations:

Illustration 6. Back action (enabled, hovered and clicked)

Back enabled picture Back hover picture Back click picture

Illustration 7. Forward action (enabled, hovered and clicked)

Forward enabled picture Forward hover picture Forward click picture  

Illustration 8. Drop down menu action (hovered and clicked)

Drop down hover Drop Down menu click picture

Collection container concept


The whole point of using navigation control is in to enable user experience of navigating through successive steps back and forth. To achieve that we have to store all those steps somewhere.  I’ve designed simple class called NavigationItem with couple of simple properties: Id, Description (which would be presented in a drop down menu – for. e.g. window title) and a Tag of object type which could be used as a session data carrier. Tag property is implemented as a virtual so it would allow overriding of storing to strong typed values 

Illustration 11. NavigationItem class diagram

Navigation item class diagram

So the goal of our control is to behave like a GUI  iterator through the collection of abstract navigation items non related to any GUI specific technology.

Project overview

During making of this example I was again following the MVP – Model View Presenter Design Pattern approach and put all the logic in separate project called VusCode.Presenters.Controls.

In short, the reason why we did it to separate in separate presenter project could be maybe a reuse in WebForm variant of this control and all the other reason stated on the posting on given link. Also I have put there all the resource files because View of our control should only know about working with generic images, so in case we would replace the resource images in presenter assembly control wouldn’t know about it, but it would still work perfectly.

So the project tree would look like

Illustration 12. Project tree

Presenter interface definition

As you can see, inside of the presenter there  is a interface IIE7Navigation which is been implemented in IE7Navigation user control and to whom the presentation class is referencing while speaking to the view. Please note that IIE7Navigation interface is inheriting IList<NavigationItem> interface as well

Illustration 13. Presenter interface

Those properties expose abstract interpretation of all the requested view functionality + collection functionality given by a List<NavigationItem> generic collection class

Illustration 16. IList<NavigationItem> implemented members

<img height=595 alt="Ilist implemented members” src=”; width=492 mce_src=”/blogs/malovicn/Images/NavigationwizzardIE7style_1261B/IListOfNavigationItem.png”>

The View

The view is implementing that interface by applying the IOD – implementation over delegation design pattern, which described in shortly is a technique of holding a private instance of a class A inside of class B and forwarding calls to a public methods of a class B to a method of class A (see the given link for more details)

Illustration 14. The view – user control structure


View is implementing the IIE7Navigation interface properties by doing something like

public Image BackButtonPicture


      set { backPicture.Image = value; }


A large number of the methods enlisted is due to the fact that we have to handle different mouse events (mouse down, mouse up, mouceover) for three different images (back forward and drop down menu pictures) 

IOD implementation of the rest not-so-trivial methods and properties is relying on forwarding all the method calls to presenter, something like this for properties

/// <summary>

/// Shows current iterator position

/// </summary>

public NavigationItem Current




            return presenter.getCurrentNavigationItem();



or for the methods


///Adds an item to the navigation item collection



///<param name=”item”>The navigation item to add to the navigation item collection.</param>

///<exception cref=”T:System.NotSupportedException”>The navigation item collection is read-only.</exception>

public void Add(NavigationItem item)




The Presenter

The presenter project contains IE7NavigationPresenter class which holds all the logic of the control.

Illustration 15. Presenter interface

We already seen that the view is implementing his functionality bu delegating his method calls to presenter, but how presenter is doing the real work?

Well it is very simple: it is delegating it further 🙂

If we take a look at the defined private fields we would see that in it there is a private field variable member navigationItemCollection of a List<NavigationItem> type so when a presenter method is been called by the view, the presenter is delegating method call by simple forwarding parameter to that private contained class method

For example presenter class is implementing Contains functionality like this

public bool Contains(NavigationItem item)


      return (navigationItemCollection.Contains(item));


Another usage of the IOD – implementation over delegation: very simple and very powerfully

The main UI look code logic is very simple (turning on and off the pics) and contained in the presenter.redraw method

/// <summary>

///  Initialize visibility of pictures

/// </summary>

private void redraw()


      if (navigationItemCollection.Count == 0) return;

      // default enabled pictures

      view.BackButtonPicture = Images.back_enb;

      view.ForwardButtonPicture = Images.forw_enb;

      view.IsDropDownMenuVisible = true;

      view.IsBackButtonVisible =

            CurrentIndex != 0;

      view.IsForwardButtonVisible =

            CurrentIndex !=

            navigationItemCollection.Count – 1;


The last important thing which needs to be mentioned is that the presenter exposes the

public event EventHandler<CurrentItemChangedEventArgs>CurrentItemChanged;

event which is generic event handler triggered by the change of iterator current position for the customized CurrentItemChangedEventArgs

Illustration 16. Event arguments

The event is been propagated to control level by implementing the view as a observer of a presenter who is raising the event.


The result

Reason why I’ve blogged about this is that I’ll use this control in my next post about Adapter and Command design pattern, but for the sake of making this article complete I’ve made very simple (but illustrative enough) example.

This testing project would be based on a simple list control where we would add some items and then walk through items by using our navigator

Illustration 17. Initial look of the test project
navigator disabled because there are no items

Intial screen

Illustration 18. One item added   – active the only one       
navigator disabled because there is only one item (nothing to navigate) but he menu item is enabled because there is a navigation item to be shown (Note that the correct tag value is shown: Item 0)

Activ only menu


Illustration 19. One item added   – active the last one      
navigator enabled and enables the back and forward buttons because there is one item before and after (Note that the correct tag value is shown: Item 1)

Illustration 20. Two items active the Frost one
after clicking on back button of navigator navigator is enabled and enables the forward buttons because there is only one item after  (Note that the correct tag value is shown: Item 0)

Illustration 21. Three item added   – active the middle one       
after adding another item and clicking forward button navigator is enabled and shows the back and forward buttons because there is one item before and after (Note that the correct tag value is shown: Item 1)

Both buttons are active

Illustration 22. Three item added   – menu active

after clicking on a menu all three items are been presented and clicking on any of them moves the navigator to that step

drop down menu

    Code used in this testing example is very simple:

a) hooking up control changed event is done like this                              

// add method to delegate event handler

IE7NavigationControl.CurrentItemChanged +=

      new EventHandler<CurrentItemChangedEventArgs>


b) adding item to navigator


NavigationItem navigationItem

      = new NavigationItem(




            (“Item:{0}” ,





c) removing item from navigator



d) handling method for a navigator control changed event

menuItemListBox.SelectedIndex =


infoLabel.Text =

That is pretty simple isn’t it and all the wizard control is been encapsulated to those three pictures. I would use this control in my next article about command and adapter pattern so you would have more time to observe this control then


Source code of the IE7Navigator control used in this example 


Model View Presenter (MVP) pattern

Update: The focus of this article is to describe the wiring between the presenter and view which are IMHO the most important thing to get for MVP pattern.
I deliberately melt down presenter and model (by having the presenter itself retrieving the user data in SetUpResultData method instead to call the separate UserRepository component) to avoid having additional service interface into the constructor pattern and making whole L100 example more complex. This is not OK outside of this example context and you shouldn’t do it.
I have one more example explaining in more depth MVP pattern which you should read after this article which has more precise description


MVP pattern is a type of UI design pattern which enables decoupling of the UI logic without UI representation and by that enables treating code base without consideration on presentation technology used.

One of the commonly stated advantages of this approach is that it enables writing of appropriate test scripts to test UI part of application. MVP enables that without the need of using third party tools which scripts user UI actions and which are fairly easy to use for testing simple actions like button click, but to write a user UI scripts for data manipulation of a grid or some more complex layout. All the logic is inside the presenter and the presenter is talking to view only through the interface, so any mock object could be used for testing as long it implements the view interface

Second advantage is the fact that by decoupling code in presenter level we are enabling reuse of the code logic to totally different presentation technologies. For the example, the same presenter can be used without any problem in both Web Form and Win Form worlds, as long as they implement agreed interface

Third advantage is in the fact that in big companies (like the one I’m working in) to implement your supportive UI code, you are often forced to wait on UX (user experience) people to make the web forms and that sometimes is a very long period. Also the way of communication between products, tech leads and developers is quite often based on some word document based FRD which (from developer perspective) is not the most precise way of specifying requirements. MVP is allowing the tech leads to crystallize results of an FRD to a set of interface definition of a view and that interface could be immediate base for developers to start coding , without waiting for anyone knowing very precise what are the requirements. (Who said TDD? 🙂 )

Illustration 1. Logical view of the MVP pattern.


Short diagram description

View is responsible for visual representation of the form and it contains a presenter in private field. View is implementing interface whose members are approximated and technology striped UI elements of the view. When some event occurs on view is just forwarding it to presenter and it is presenter responsibility to handle the event. Presenter is manipulating view by talking to interface representation of the view. Presenter should never reference directly view members (UI controls). Presenter for his logic operations is using Model which can be persisted state or representation of the object which provides necessary functionality

Implementation procedure:

Create a view by using standard Visual Studio IDE tools.

For my example I will create first a web form with:

    • a label on top which would show possible validation error
    • Last name, first name, address and a city text boxes
    • Search text box with a button

Illustration 2. UI look of the view made by web form

Interface would be created in a separate project called presenter so we could reuse it later to demonstrate usage outside of our web application. Web application should have a reference to the presenter project

Illustration 3. Project structure  – separating and referencing presenter

Create a interface as an abstract form of a view with setters only for text boxes (because presenter would fill == set them) and getter property only for searcher (presenter would take that value and perform a search)

Illustration 4. View interface definition

namespace Presenter


    public interface IUserView


        string FirstName { set;}

        string LastName { set;}

        string Address { set;}

        string City { set;}

        string ErrorMessage { set;}

        string SearchCriteria { get;}



After creation of interface we are implementing it on view by setting and getting UI element values in the property

Illustration 5. View interface implementation

    #region IUserView Members

    public string FirstName


        set { firstName.Text = value; }


    public string LastName


        set { lastName.Text = value; }


    public string Address


        set { address.Text = value; }


    public string City


        set { city.Text = value; }


    public string ErrorMessage




            errorMessageLabel.Text = value;

            errorMessageLabel.Visible = value != “”;



    public string SearchCriteria


        get { retur
searchCriteria.Text; }



Creation of presenter class includes creation of a private field of view interface type and overloading of a constructor to accept that view interface

Illustration 6. Presenter  wiring the view

 namespace Presenter


    public class UserViewPresenter


        IUserView _view;

        /// <summary>

        /// Initializes a new instance of the UserViewPresenter class.

        /// </summary>

        /// <param name=”view”></param>

        public UserViewPresenter(IUserView view)


            _view = view;



Presenter would have to implement business logic, which In our example is finding of a customer for a given code. I’ve created Customer.xml file as D:Customer.XML

Illustration 7. Exampled data used for sample 

Presenter would implement therefore a method named SetCustomerData which task is to find a customer of a given code and update the view with resulting data. In case the entered code is not a valid number presenter would show appropriate message on validator that there is a syntax error. In case there are no contacts with a given code presenter should empty view and show a message that not existing code has been entered.

Illustration 8. Implementation of a presenter logic 

public void SetCustomerData()


int searchCode;

      bool isValid = int.TryParse

            (_view.SearchCriteria, out searchCode);

if (isValid)


            using (DataSet ds = new DataSet())


                  string filePath=string.Format(






                        = new DataColumn[]


                        DataRow dr=



if (dr != null)



                           = dr[“FirstName”].ToString();


                           = dr[“LastName”].ToString();


                           = dr[“Address”].ToString();


                           = dr[“City”].ToString();


                           = “”;




                        _view.FirstName = _view.LastName

                            = _view.Address = _view.City = “”;


                            = “Contact not existing”;






            _view.FirstName = _view.LastName =

            _view.Address = _view.City = “”;

            _view.ErrorMessage = “Not a valid code!!!”;



Presenter would implement therefore a method named SetCustomerData which task is to find a customer of a given code and update the view with resulting data. In case the entered code is not a valid number presenter would show appropriate message on validator that there is a syntax error. In case there are no contacts with a given code presenter should empty view and show a message that not existing code has been entered.

Illustration 9. Results of an example – Code 1 entered – user shown

Illustration 10. Results of an example – Non existing valid code entered


Illustration 11. Results of an example – Invalid code entered

Now I will show reuse of the presenter for implementing the same logic in totally different technology: WinForm

I’ll slightly change the look by switching the places between search criteria and the error message and city would be presented now by ComboList

Illustration 12. UI look of the view made by windows form

Usage of MVP patterns allows me just to implement view interface to win form and to view up presenter by passing to its constructor WinForm and all the same functionality is present without touching a presenter. That’s why the presenter is speaking to interface which shouldn’t be technology specific

Illustration 13. Wiring up the win form view to the presenter

using System.Windows.Forms;

using Presenter;

namespace WinForm


    public partial class UserViewForm : Form, IUserView


        private UserViewPresenter _presenter;

        public UserViewForm()



            _presenter = new UserViewPresenter(this);




        private void searchButton_Click(object sender, System.EventArgs e)




        #region IUserView Implementation

                  // The same implementation like in WebForm case

                  // Wire up the control text properties to interface members





So the complete solution would be something like:

Illustration 13. Complete project tree

And the result is the same functionality encapsulated in presenter is been reused for a win form

Illustration 14. Results of an example in win form – Existing code entered

Illustration 15. Results of an example in win form – Non existing code entered

Illustration 16. Results of an example in win form – Invalid code entered


MVP is very powerful UI design pattern which has multiple benefits for developing all kinds of user interfaces. That is the reason why CAB (Composite Application Block) is
using it as a one of basic UI building principles 


Source code of the MVP application used in this example  


Google webmaster tools – SiteMap generator

Download source code at: Google Site Map Console Application Source

To make your web site visible to Google crawler you have to update a site map to Google. Site map file  is basically an xml file which contains the list of specific url which crawler is supposed to visit

An example of an sitemap file contain could be

<?xml version=”1.0″?>
<urlset xmlns=”″&gt;















To create a site map file you could use a simple console application like this one

using System.Xml;

using System;

namespace ConsoleApplication1


    class Program



        static void Main(string[] args)


            using (XmlTextWriter xmlWriter = new XmlTextWriter(@”D:Sitemap.xml”,null))


                xmlWriter.Formatting = Formatting.Indented;




                // adding of first site map item

                WriteSiteMapItem(xmlWriter, @”;);

                // adding of second site map item

                WriteSiteMapItem(xmlWriter, @”;);






        private static void WriteSiteMapItem(XmlTextWriter xmlWriter,string siteMapItemUrl)


            string now = string.Format(“{0}{1}”, TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now).ToString(“s”), “+00:00”);


            xmlWriter.WriteElementString(“loc”, siteMapItemUrl);

            xmlWriter.WriteElementString(“lastmod”, now);

            xmlWriter.WriteElementString(“changefreq”, “always”);

            xmlWriter.WriteElementString(“priority”, “0.8”);





Resulting site map is then to be uploaded through  Google web site dedicated to web master support.

You have to:

a) login with your Google account,

b) add your site url,

c) verify that you are the owner by creating an empty html file with given specific name,

d) create and upload site map file with some generator like the one I’ve exampled


And for all blogs hosted on CS Mr Dan Bartel made a nice add in which does this automatically

Welcome a board mate!

Community server is been set it up and working well, so no more excuses for me not to start my project of documenting my explorations of a beautiful .NET world

My name is Nikola Malovic and I’m working in as a software engineer. I’m fascinated with Smart Client architecture and basically with all of the p & p stuff. I Like to learn about architecture stuff. MCSD since 2002.

I would try to put as much as possible all kinds of different articles in different areas and level of knowledge. I will start with Smart Client Factory posting which would include explanation of related patterns. I’m planing to post a screencast for the most of my posts, because I felt on my own skin how good is for learning to observe another programmer typing code

On the top of my web site I’m offering rss feeds link so you could add them to your fire fox browser, Outlook 2007, IE7 or some other feed reader.

So, stay tuned

Nikola Malovic