0

Let me start by doing a small summary of the changes we did in our code in the last year. We have a software (VERY big) that is used to visualize multiples underground networks, enter data in the entities in the network and create simulation in this network.

In the 20 years of development of this application (in MFC C++), multiple people have worked on it, lots of patch have been done and it's in constant developpement. Over the year, a monster class has been created. The class is called "CNetwork" and each network is a subclass of it.

To illustrate this moment in the code history, the prototype of a typical dialog was this:

public SuperNiceDialog(int nID, CNetwork* pNetwork);

After a course on unit testing, it was obvious for me that we needed to create interface to make everything more testable. Since most of our "functionnality" were in the network,CNetwork was implementing a lot of them and now when we need to call the same dialog, it looks like this:

public SuperNiceDialog(int nID, ITranslateNetwork* pTranslate,
                        IUnitManager* pUnitManager,
                        ICommonVectorProviderAQ* pCommonVectorProviderAQ,
                        INetworkInfo* pNetworkInfo,
                        IDatabaseManager* pDatabaseManager,
                        ISimulation* pSimulation,
                        INetworkAutonumerotation* pNetworkAutonumerotation,
                        ISpreadsheetInfoProvider* pChiffrierInfoProvider,
                        IPolygonManager* pPolygonManager,
                        ISetterValidation* pSetterValidation)

I will not unit test a dialog but a lot of class called inside this dialog could be tested but for most of them, I must passe a lot of interface to get the work done. And I can't juste pass the network because some of the interface are removed from CNetwork to slowly remove functionnality from a single class.

So we think about it and one of the ideas that we had was to create a "package" object which could be a simple structure containing pointers to interfaces and getter to get access to these pointers (Like a Facade object). For example

My dialog would be called like this

public SuperNiceDialog(int nID, CDialogInterfacePackage* pPackage)

And in the code, I would use it like that

m_pPackage->GetITranslation()->Translate(123456);

Since most of the Dialog needs the same interface, we could put 10 interfaces in it and just pass this to the dialog. We could create "interface package" for various module for example for simulation, spreadsheet, etc..

One part of me think it's a good idea but another part is telling me that I will be slowly creating a new "CNetwork" in some kind of way... Any idea about this problem of having too much interfaces? Is this a good approach?

Thanks

  • I'm not seeing the problem with what you have. You can easily mock out any interfaces you're not using in any given test (and if you're doing that a lot, you can use an auto-mocking framework, or just a builder method). Interface Segregation Principle prefers what you have now to what you're proposing. – pdr Mar 21 '14 at 17:20
  • @pdr: What he's proposing is essentially a View Model. – Robert Harvey Mar 21 '14 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.