views:

114

answers:

1

Hi, I'm working on a database upgrader application. The upgrader updates the schema of a database ( adds new columns, renames columns , adds new tables, new views to an existing database by executing SQL statements ). When a user wants to upgrade from version 1.0 to 2.0 , "Upgrader" objects are taken from an object factory and the "Execute" method of each "Upgrader" is called. The GUI of the application has a progress bar and each time an upgrader object performs a SQL statement the progress bar gets incremented.

            while (!version.Equal(CurrentVersion))
            {

                 IUpgrader myUpgrader = UpgraderFactory.GetUpgrader(version);

                 myUpgrader.Execute(UpgradedFile,progressbar);

                 version.Increment();
            }

My question is very simple : how should the upgrader object communicate with the progressbar. In the code above, the upgrader object is given direct access to the progressbar but I'm wondering if some better way of doing this or better design pattern exists.

Regards, Seb

+2  A: 

I would probably put together an interface for progress bar operations (C# sample):

interface IProgressBar
{
     int MinValue { get; set; }
     int MaxValue { get; set; }
     int Value { get; set; }
}

Then I would have the Upgrader object take a parameter of that interface type. Lastly I would create a class that implements the interface, and that also holds a reference to the progress bar component that it uses to visualize the progress.

That way you will have no tight coupling between the upgraders and how the progress is visualized.

Fredrik Mörk