C
Chris Thomasson
Consider an an object that that can has 7 or 8 functions. If you create an
abstract base class for the "interface" of the object, well, that means 7 or
8 pure virtual functions right? Well, IMHO, that's way too much... I was
wondering if the following technique is "frowned" upon:
<pseudo-code>
_____________
typedef struct ... vztimespec_t;
class condmutex_base {
public:
enum wait_e {
WAITLOCK, TRYLOCK, WAITCOND
};
enum wake_e {
UNLOCK, SIGNAL, BROADCAST
};
protected:
condmutex_base() {}
public:
virtual ~condmutex_base() {}
private:
virtual bool wait(wait_e, vztimespec_t const*) = 0;
virtual bool wake(wake_e) = 0;
public:
inline void unlock() { wake(wake_e::UNLOCK); }
inline void waitlock() { wait(wait_e::WAITLOCK, 0); }
inline void waitcond() { wait(wait_e::WAITCOND, 0); }
inline bool trylock() { return wait(wait_e::TRYLOCK, 0); }
inline bool signal() { return wake(wake_e::SIGNAL); }
inline bool broadcast() { return wake(wake_e::BROADCAST); }
inline bool timedwaitcond(vztimespec_t const *tspec) {
return wait(wait_e::WAITCOND, tspec);
}
};
_____________
I only have 2 virtual functions now, not counting dtor, ect... Well, 2 is
better than 7, or 8?
Any thoughts?
:^)
abstract base class for the "interface" of the object, well, that means 7 or
8 pure virtual functions right? Well, IMHO, that's way too much... I was
wondering if the following technique is "frowned" upon:
<pseudo-code>
_____________
typedef struct ... vztimespec_t;
class condmutex_base {
public:
enum wait_e {
WAITLOCK, TRYLOCK, WAITCOND
};
enum wake_e {
UNLOCK, SIGNAL, BROADCAST
};
protected:
condmutex_base() {}
public:
virtual ~condmutex_base() {}
private:
virtual bool wait(wait_e, vztimespec_t const*) = 0;
virtual bool wake(wake_e) = 0;
public:
inline void unlock() { wake(wake_e::UNLOCK); }
inline void waitlock() { wait(wait_e::WAITLOCK, 0); }
inline void waitcond() { wait(wait_e::WAITCOND, 0); }
inline bool trylock() { return wait(wait_e::TRYLOCK, 0); }
inline bool signal() { return wake(wake_e::SIGNAL); }
inline bool broadcast() { return wake(wake_e::BROADCAST); }
inline bool timedwaitcond(vztimespec_t const *tspec) {
return wait(wait_e::WAITCOND, tspec);
}
};
_____________
I only have 2 virtual functions now, not counting dtor, ect... Well, 2 is
better than 7, or 8?
Any thoughts?
:^)