dimanche 15 février 2015

Definig a Null object without inheriting an interface

We are building in C++ a simulator that implement only some of the functionalities of the real objects, and we are trying to build it as slim as possible on one hand, but trying to make as least changes in the original code on the other hand.


Some of the objects in the design are extremely big, and our simulator does not need to use them. moreover, they are consuming a lot of memory and CPU.


The most obvious way to solve this is to make these objects an interface, and build some new NULL objects inherinig the interface. But this solution has a few drawbacks:



  • We'll need to change some legacy objects for that purpose.

  • We'll have to define all the functions of the used object, and all it's structure both in the interface and in the dummy inheritors, so we can keep calls like hugeObject->getA()->getB()->getValue() at place


Using templates instead of an interface may solve the first problem, but not the second one.


Is there a better design which will not require an extreme rearrange with the entire existing code ?


I hope the question is clear enough. Please tell me if it's not clear and I'll add an example with a UML chart.


Aucun commentaire:

Enregistrer un commentaire