leveldb log_reader.h/Reader class design consideration

52 views
Skip to first unread message

陈宗志

unread,
Dec 26, 2016, 1:16:28 PM12/26/16
to leveldb

I find class Reader design this way. we have a class name Reader, then we provide an interface class Reporter


class Reader {
...
class Reporter {
   public:
    virtual ~Reporter();

    // Some corruption was detected.  "size" is the approximate number
    // of bytes dropped due to the corruption.
    virtual void Corruption(size_t bytes, const Status& status) = 0;
};
};

why should we design this way? In my intuition I will provide a pure virtual function Corruption in class Reader?


class Reader {

virtual void Corruption(size_t bytes, const Status& status) = 0;
};

Then if I want to use class Reader, I will inheritance from class Reader, and provide my own implementation of Corruption.

I think the difference here is that, if we do the way leveldb db, the user only need to know how to implement the Reporter interface. But in my inheritance from class Reader, the user need to know the whole class Reader.

So the leveldb way provide more encapsulation.

Is this the right consideration in leveldb's design

Reply all
Reply to author
Forward
0 new messages