class design/ design pattern question

  • Thread starter Bartholomew Simpson
  • Start date
B

Bartholomew Simpson

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 ... ?
 
V

Victor Bazarov

Bartholomew said:
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
 
D

Daniel T.

Bartholomew Simpson said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top