C
Carl Bevil
I'm creating a library for internal use that relies on third-party code. I
don't want clients of this library to know anything about the third party
code, when compiling or running. Generally I've been achieving this by having
an abstract base class which defines an interface, and inheriting a concrete
class which defines the implementation. Clients of the library deal only with
the base class and request objects of that type from a factory function.
This works great in most cases. The problems set in when you have operator
overloading. For example, I might have a class which defines 2-dimensional
point on the screen. I want the user to be able to use operator+, operator==,
operator=, etc... on this class.
Scanning the archives of this newsgroup it seems the big problem comes into
play with operator=, although I still see problems with the other operators as
well.
Hopefully what I'm saying is clear; if not, please let me know.
What I'm trying to do is analogous to:
class Point
{
virtual void function(int x) = 0;
}
class PointImplemenation
{
virtual void function(int x);
}
except with operators:
class Point
{
virtual Point operator+(const Point& pt) = 0;
}
class PointImplementation
{
virtual PointImplementation operator+(const PointImplementation& pt);
}
I don't think this is going to work well at all, and it looks like a recipe
for many headaches in the future.
Anyone have an elegant solution for this problem? I've thought of the
possibility of using a proxy object instead of direct inheritance, although
that's not so great either, IMO.
I'm open to any ideas.
Thanks!
Carl
don't want clients of this library to know anything about the third party
code, when compiling or running. Generally I've been achieving this by having
an abstract base class which defines an interface, and inheriting a concrete
class which defines the implementation. Clients of the library deal only with
the base class and request objects of that type from a factory function.
This works great in most cases. The problems set in when you have operator
overloading. For example, I might have a class which defines 2-dimensional
point on the screen. I want the user to be able to use operator+, operator==,
operator=, etc... on this class.
Scanning the archives of this newsgroup it seems the big problem comes into
play with operator=, although I still see problems with the other operators as
well.
Hopefully what I'm saying is clear; if not, please let me know.
What I'm trying to do is analogous to:
class Point
{
virtual void function(int x) = 0;
}
class PointImplemenation
{
virtual void function(int x);
}
except with operators:
class Point
{
virtual Point operator+(const Point& pt) = 0;
}
class PointImplementation
{
virtual PointImplementation operator+(const PointImplementation& pt);
}
I don't think this is going to work well at all, and it looks like a recipe
for many headaches in the future.
Anyone have an elegant solution for this problem? I've thought of the
possibility of using a proxy object instead of direct inheritance, although
that's not so great either, IMO.
I'm open to any ideas.
Thanks!
Carl