Database Facade to wrap our existing queries?

We have a very big application written in C++ using the MFC framework (millions of code lines). No need to say that it’s a legacy system, but it’s also heavily maintained and updated. This application lacks a lot of architecture. For example, we have a lot of classes that do queries directly to the database, which creates a lot of difficulty for unit testing.

I have read the book Working Effectively With Legacy Code, and one of the most important things to do first is to create some kind of architecture so we can separate the GUI from the logic and from the database.

My idea to go towards this is to create something like a database facade. There will be 2 goals for this:

  1. Encapsulate all the calls to the database behind this facade.
  2. Be able to test the facade in batch to detect errors in the SQL very fast.

The database facade itself will be implementing an IDatabaseXXXX interface so it could be easily mocked in the unit tests. The second goal will be to be able to run all the functions in the facade in batch to test if there are errors in the SQL queries. I don’t count them as unit tests and would be running them only once per day.

My main concern about doing this is that I don’t know if there is an existing framework or library to take care of this abstraction. As far as I know, there are some on other platforms like .NET, but it seems that for C++ or MFC, there are not a lot of options. Like I said, the application is very big and the change will be done slowly, mostly when new queries are added to the software.

I think it is a good thing to add that we also have a LOT of recordsets (one for almost each object). For the moment, I don’t know how to deal with them, so I kept them on the side and decided to deal with the regular SQL queries. But if you have suggestions to deal with recordsets, I will be glad to hear them.

So my main question is: Is this whole idea of database facade worth trying? Is there any library of framework to help me in this adventure? If there are C++/MFC programmers out there, how do you deal with the abstraction of the query to the database?

Thanks!

EDIT

Some people on the chat suggest looking up at repository pattern which I knew from the world of MVC 3. Any suggestion or tutorial about the repository pattern in C++? Most of what I found is in the .NET world.

4

As your update suggets, the repository pattern would be able to help seperate the database calls from your UI. And replacing the database calls with calls to an IDatabase interface is certainly an improvement. The repository pattern will allow you to further abstract the the data retrieval into something meaningful to the application. UserRepository, ThingRepository, etc.

http://msdn.microsoft.com/en-us/library/ff649690.aspx

As an approach to implementing this architecture. When I need to make code testable to refactor the first test is always the hardest. Find a well understood piece of code that you want to test and make that class/method testable. Once this is in place it is persistence and patience that will allow you to complete the task of introducing the new architecture into the legacy system.

I have read the book Working Effectively With Legacy Code, and one of the most important
things to do first is to create some kind of architecture so we can separate the GUI from
the logic and from the database.

That would be how to read the legacy code and then rewrite the system in a new platform. But you can’t honestly expect to actually do this in the legacy code itself. Adding architecture to legacy code after the fact…that just doesn’t sound feasible in the real world.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật