0

I have a set of classes that are replies from the network. Some classes uses function foo, while others use bar. I was thinking of just have a class that sets the variable inside foo and bar. Then inherit those classes which just only have function foo and bar functions without constantly defining the functions in those classes. For example.

class Foo {
public:
    Foo():
        foo_(std::string()) {}
    virtual ~Foo(){}
    const std::string& foo() const { return foo_; }
private:
    std::string foo_;
};

class FooReply:
    public Foo {
public:
    FooReply(){}
    explicit FooReply(const std::string& reply):
        setFoo(reply) {
    }
    FooReply(const FooReply& other):
        Foo(other) {
    }
    ~FooReply(){}
    FooReply& operator=(const FooReply& other) {
        Foo::operator=(other);
        return *this;
    }
};

Would it be better to do this, or should I just make them an interface and just reimplement the foo() function? Since I'm only inheriting one function.

Zeke
  • 51
  • 1
  • 5
  • And what's the question exactly? – littleadv Dec 18 '11 at 03:15
  • I think that using `Foo` as a member will be better – user685684 Dec 18 '11 at 03:30
  • 1
    Really confused what you're asking... can you state it a bit more clearly? Perhaps with two examples? – bdonlan Dec 18 '11 at 03:31
  • @bdonlan Basically, I have a set of replies as classes. When I receive a reply from the network. I will send one of my reply classes to then user/my client. Not all of these classes have the same functions in them. I was just wondering, if I should just inherit the class with that one function I need and just set it in the derived class, or just continue with reimplementing the function of and other with an interface? By inheriting it (not as an interface), i'll be able to get away with creating the variable to hold the info, but calling setFoo instead, since I'm using dpointers for bin compat – Zeke Dec 18 '11 at 03:42

0 Answers0