Software Design and Tests

Introduction


Programming paradigms:
  • procedural, functional, object oriented, generic, differentiate…

Building blocks:
  • Polymorphism: Adhoc, Parametric, Sub-typing, Duck typing, Concepts…
  • Inheritance, composition, aggregation, delegation, injection
  • Side effects, RAII, memory ownership, 
  • reentrancy, thread safety …

Language and paradigm do not really matter. 
We focus on feature sets and how it affects testability.

OOP with Unit testing →

(typical “programming style” in our C++ code base)
struct IClassifier {
  virtual double predict(cv::Mat img) = delete;
  virtual ~IClassifier() = default;
};
struct IBGModel { ... virtual ~IBGModel() = default; };
struct PackageDetector {
  PackageClassifier(const std::shared_ptr<IClassifier>& classifier,
                    const std::shared_ptr<IBGModel>& bgModel)
    : _classifier(classifier), _bgModel(bgModel) {}

  bool hasPackage(const Video& video) {
    for (const auto& zone : _bgModel->getStaticZones(video)) {
      if (_classifier->predict(zone.getImage()) > THRESHOLD) 
          return true;
    }
    return false;
  }
 private:
  std::shared_ptr<IClassifier> _classifier;
  std::shared_ptr<IBGModel> _bgModel;
};

Boring C++ Questions ?
  • Why interfaces are structs ?
  • Why interfaces define virtual destructors ? = default ?
  • Why shared_ptr and not pointers or references ? std::unique_ptr ?
  • Other questions ?

Why ‘classifier' and 'bgmodel’ are passed to the constructor and not used directly ? 

Software Design

S.O.L.I.D. design + others