Turn class "Interfaceable"

Posted by scooterman on Stack Overflow See other posts from Stack Overflow or by scooterman
Published on 2009-12-28T16:04:37Z Indexed on 2010/03/18 0:51 UTC
Read the original article Hit count: 362

Filed under:
|

Hi folks,

On my company system, we use a class to represent beans. It is just a holder of information using boost::variant and some serialization/deserialization stuff. It works well, but we have a problem: it is not over an interface, and since we use modularization through dlls, building an interface for it is getting very complicated, since it is used in almost every part of our app, and sadly interfaces (abstract classes ) on c++ have to be accessed through pointers, witch makes almost impossible to refactor the entire system.

Our structure is:

dll A: interface definition through abstract class
dll B: interface implementation

there is a painless way to achieve that (maybe using templates, I don't know) or I should forget about making this work and simply link everything with dll B?

thanks

Edit: Here is my example.
this is on dll A
BeanProtocol is a holder of N dataprotocol itens, wich are acessed by a index.

class DataProtocol;

class UTILS_EXPORT BeanProtocol
{
public:
  virtual DataProtocol& get(const unsigned int  ) const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual void getFields(std::list<unsigned int>&) const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual DataProtocol& operator[](const unsigned int )
  {
    throw std::runtime_error("Not implemented");
  }

  virtual DataProtocol& operator[](const unsigned int ) const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual void fromString(const std::string&) 
  {
    throw std::runtime_error("Not implemented");
  }

  virtual std::string toString() const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual void fromBinary(const std::string&)
  {
    throw std::runtime_error("Not implemented");
  }

  virtual std::string toBinary() const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual BeanProtocol& operator=(const BeanProtocol&)
  {
    throw std::runtime_error("Not implemented");
  }

  virtual bool operator==(const BeanProtocol&) const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual bool operator!=(const BeanProtocol&) const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual bool operator==(const char*) const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual bool hasKey(unsigned int field) const
  {
    throw std::runtime_error("Not implemented");
  }
};

the other class (named GenericBean) implements it. This is the only way I've found to make this work, but now I want to turn it in a truly interface and remove the UTILS_EXPORT (which is an _declspec macro), and finally remove the forced linkage of B with A.

© Stack Overflow or respective owner

Related posts about c++

Related posts about interface