f



class design/ design pattern question

I have a class which takes a while to instantiate (reads from shmmem, 
then connects to db etc). I call this a "heavy" class. I would like to 
use a "lightweight" version of the class - so that I can (for example), 
create consts in my code, for reuse - however, I want to be able to 
convert the lightweight object into a heavy weight counterpart, when I 
need to do some rare stuff.

I remember coming accross a DP that allows one to do this but - and I 
can't locate it in the GoF constructional patterns ... ?
0
6/12/2007 2:34:38 PM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

2 Replies
438 Views

Similar Articles

[PageSpeed] 15

Bartholomew Simpson wrote:
> I have a class which takes a while to instantiate (reads from shmmem,
> then connects to db etc). I call this a "heavy" class. I would like to
> use a "lightweight" version of the class - so that I can (for
> example), create consts in my code, for reuse - however, I want to be
> able to convert the lightweight object into a heavy weight
> counterpart, when I need to do some rare stuff.
>
> I remember coming accross a DP that allows one to do this but - and I
> can't locate it in the GoF constructional patterns ... ?

I don't think GoF book has anything like that.  What you're describing
looks like "lazy initialisation".  Delayed computation is the corner
stone of some optimizations.  Don't compute what you're not going to
use, that's generally a good idea.

Sorry, I can't help you much, but perhaps somebody in the newsgroup
'comp.software.patterns' can?

V
-- 
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask 


0
v.Abazarov (13256)
6/12/2007 3:52:13 PM
Bartholomew Simpson <123evergreen@terrace.com> wrote:

> I have a class which takes a while to instantiate (reads from shmmem, 
> then connects to db etc). I call this a "heavy" class. I would like to 
> use a "lightweight" version of the class - so that I can (for example), 
> create consts in my code, for reuse - however, I want to be able to 
> convert the lightweight object into a heavy weight counterpart, when I 
> need to do some rare stuff.
> 
> I remember coming accross a DP that allows one to do this but - and I 
> can't locate it in the GoF constructional patterns ... ?

The "Proxy pattern" is what you are describing.
0
daniel_t (1960)
6/12/2007 8:51:51 PM
Reply: