mercredi 19 août 2015

What is insulation?

I know in c++ there is some "coding style" (I don't exactly know what it should be called) called insulation, I know something about that but not really understand what it is doing.

I know one of target of insulation is to "include as late as possible", one of the example is using pointer in class member:

before insulation:

#include "B.h"
class A{
    B b;
};

after insulation:

class B;
class A{
    B* b;
};

so that it can delay the include of B and no need to include B if another class include A.

But I often saw another insulation example that separate a class XXX into 2 files:XXX and XXXImp like that (I am not sure if it is separating like that):

//before insulation

class A{
public:
    a();
private:
    int b;
    c();
};

//after insulation

class A{
public:
    a();
}

class AImp : public A{
private:
    int b;
    c();
};

A has already no extra .h to import, why is it necessary to separate the public and private member to 2 classes? Why it is called insulation?

Aucun commentaire:

Enregistrer un commentaire