atomic
17th October 2015, 17:45
Hi all,
In my company I started implementing a library where some of classes should inherit from Qt classes.
I look on source code for example of QAuthenticator class and I see that it does not use interface ( does not inherit any interface / pure abstract class ) but use PIMPL idiom ( it is fine ).
And now when I want for example change the QAuthenticator implementation without change public API of this class I can not do that.
I would like ask you if do you think that good library should be build using interfaces and PIMPL idiom? For example:
class IAuthenticator
{
public:
virtual ~IAuthenticator() {}
virtual QString user() const = 0;
virtual void setUser(const QString &user) = 0;
virtual QString password() const = 0;
virtual void setPassword(const QString &password) = 0;
// etc ...
};
class AuthenticatorPrivate
{
public:
QString method;
QString user;
QString password;
QString realm;
};
class Authenticator : public IAuthenticator
{
public:
// ...
private:
QScopedPointer<AuthenticatorPrivate> d; // d-pointer == PIMPL
};
In my company I started implementing a library where some of classes should inherit from Qt classes.
I look on source code for example of QAuthenticator class and I see that it does not use interface ( does not inherit any interface / pure abstract class ) but use PIMPL idiom ( it is fine ).
And now when I want for example change the QAuthenticator implementation without change public API of this class I can not do that.
I would like ask you if do you think that good library should be build using interfaces and PIMPL idiom? For example:
class IAuthenticator
{
public:
virtual ~IAuthenticator() {}
virtual QString user() const = 0;
virtual void setUser(const QString &user) = 0;
virtual QString password() const = 0;
virtual void setPassword(const QString &password) = 0;
// etc ...
};
class AuthenticatorPrivate
{
public:
QString method;
QString user;
QString password;
QString realm;
};
class Authenticator : public IAuthenticator
{
public:
// ...
private:
QScopedPointer<AuthenticatorPrivate> d; // d-pointer == PIMPL
};