List:MySQL++« Previous MessageNext Message »
From: Date:January 1 1970 12:00am
Subject:locable.h: strange design dessision??
View as plain text  
Hi,
I tried to review some code inside mysqlpp and possibly modify it for me 
(I want to replace some parts with code from other libraries, eg 
boost.date_time etc, since I use date_time in my app) and I found some 
strange code

class Lock, BasicLock, and Locable are strange pieces of code in my 
point of view. First of all, there's no need to have virtual methods for 
such simple class. Locable has a really doubtful piece of code - it 
creates BasicLock using new! I find it to be really strange, as I don't 
see any need to have pointer to an object that's one byte in size. 
Perhaps, the intention was to have possibility replace underlying Lock 
with some other Lock object, but isn't it's strange to change threading 
models at runtime? As with my first mail I may be wrong without knowing 
the underlying code, but why it was designed this way? I think I never 
saw anything like this.
This issue is well discussed in "Modern C++ Design" and loki-lib has 
some good code for implementing it.
basically, from this book it seem that a better decision is:
template<template <class> ThreadingModel>
class connection : ThreadingModel<connection> {}

and inside connection::method(){
	lock(*this);
	//do something...
}
Thread
locable.h: strange design dessision??Unknown Sender19 Sep
  • Re: locable.h: strange design dessision??Warren Young19 Sep
    • Re: locable.h: strange design dessision??Unknown Sender19 Sep
      • Re: locable.h: strange design dessision??Warren Young19 Sep