473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Breaking Dependencies on Legacy Code

Hello,

I have a rather big application with many processes and have to add some
features. I want to put some classes of it into a test harness with
cppunit and need to break some dependencies on a vendor GUI library.
Maybe someone has some thoughts on this.

Suppose there is a GUI class from the vendor library:

// Sheet.h:
class Sheet /*: public Matrix*/
{
public:
Sheet();
virtual ~Sheet();

virtual void draw();
void setSomething();
virtual void someCallback();
};

which is part of a greater hierarchy. It has virtual methods,
non-virtual methods and some virtual callback methods.

The application then inherits from this class something like that:
// EntrySheet.h
#include <iostream>
#include "Sheet.h"
class EntrySheet : public Sheet
{
public:
EntrySheet() : Sheet()
{}

virtual ~EntrySheet();

virtual void someMoreMemberFunc();

virtual void someCallback()
{
std::cout << "Callback called" << std::endl;
}
};

//EntrySheet.cpp:
#include "EntrySheet.h"

void EntrySheet::someMoreMemberFunc()
{
// do something
}
So nothing exciting here. For putting this class in a test harness I
want to get rid of the GUI class and replace it with a dummy class which
is more suitable for testing.

My first idea was to change EntrySheet to something like this:

//EntrySheet.h:
#include "Sheet.h"

template<typename T>
class EntrySheet : public T
{
public:
typedef T Inherited;

EntrySheet() : Sheet()
{}

virtual ~EntrySheet();

virtual void someMoreMemberFunc();

virtual void someCallback();
};
#include "EntrySheet.cpp"
//EntrySheet.cpp:

template<typename T>
void EntrySheet<t>::someMoreMemberFunc()
{
//do something
}
Then the class can be used in the production code with:

#include "Sheet.h"
#include "EntrySheet.h"

typedef EntrySheet<SheetIEntrySheet;

int main(int argc, char** argv)
{
IEntrySheet sheet;

sheet.setSomething();
sheet.someMoreMemberFunc();
sheet.draw();

return 0;
}
For the test harness only the typdef needs to be changed

#include "DummySheet.h"
#include "EntrySheet.h"

typedef EntrySheet<DummySheetIEntrySheet;

int main(int argc, char** argv)
{
IEntrySheet sheet;

// perform tests

return 0;
}
This method works and the advantages are, that it is relatively easy to
implement and in DummySheet there need only the member functions to be
implemented, which are really referenced (Sheet is rather big).

The big disadvantage is, that EntrySheet is rather big too and in the
template version it has to be included everytime it is used which
increases compile time, especially if this dependency breaking method is
used for more classes.

In "Working effectively with legacy code" Michael Feathers suggests to
use wrappers for vendor libraries, but this seems not feasible because I
need the inheritance to get the someCallback() call from somewhere in
the vendor library hierarchy.

Any thoughts on other methods which allow an easy switching between
dummy and real class for testing and that don't increase the compile time?
lg,
Michael
Apr 17 '07 #1
2 1532
Michael Oswald wrote:
The big disadvantage is, that EntrySheet is rather big too and in the
template version it has to be included everytime it is used which
increases compile time, especially if this dependency breaking method is
used for more classes.
That's a smell of its own that needs dealing with. Split the class up
first and put its individual components under harness. You might then
not need put the sheet in at all.
Apr 18 '07 #2
Noah Roberts schrieb:
That's a smell of its own that needs dealing with. Split the class up
first and put its individual components under harness. You might then
not need put the sheet in at all.
Good point. I'll have a look what's possible.

lg,
Michael
Apr 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JellBell | last post by:
I dont know what is a legacy system..please help me out Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION...
7
by: Brian Sabolik | last post by:
I'm not sure if I've broken any Object Oriented rules or not, but ... I have projects in 2 different solutions that need to use each other's methods. Therefore I may have an "update" method in...
3
by: masood.iqbal | last post by:
In this day and age, you never say no to any work that is thrown at you ---- so when I was offered this short-term contract to convert legacy C code to C++, I did not say no. Personally I believed...
3
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached...
4
by: Scott | last post by:
I need a way to find all the database dependencies (stored procs, tables, and views) used by my assemblies. I don't expect to get a perfect solution since it's possible that stored proc names and...
3
by: K.K. | last post by:
Consider the following code: >>>>>>>>>>> // Define an empty class public class ZorgleCollection : Dictionary<string, Zorgle> { } // Somewhere outside ZorgleCollection:
2
by: Mark Olbert | last post by:
First off, the sympathy is for all you poor buggers out there who have to figure out how to marry Managed Extensions for C++ onto your legacy code. My condolences; my brief experience with the...
150
by: tony | last post by:
If you have any PHP scripts which will not work in the current releases due to breaks in backwards compatibility then take a look at http://www.tonymarston.net/php-mysql/bc-is-everything.html and...
1
by: dragze | last post by:
Hi, On one of the pages of my site i use two javascripts, one makes transparency of png's work in IE, and the other embeds a flash player. Now use one of the scripts it works fine, use both and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.