Memento to store current state, not just bookmarked state?

S

Samuel R. Neff

Is there any downside to using the Memento pattern to store the
current state of an object instead of using private fields for
internal state and a memento just for some bookmarked state?

Seems like the upside is less code and easier state
management/cloning. Perhaps there's a slight performance difference
with accessing the memento's fields instead of local private fields,
but that should be insignificant.

Thanks,

Sam

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
M

Mohammad

Well, there's one condition that must be met:
The interface for your classes if implemented using the memento
pattern should be identical to the interface if they were implemented
with plain old fields.

And memory and performance issues aside, there's one downside:
Added complexity.

For the memento pattern to be justified, your application would have to
be using a huge amount of objects that are immutable, and are large
enough in terms of memory footprint. The number and state of those
objects must also be known at design time.

If all of the above is met, then you should be able to save yourself
some memory by using the memento pattern.

But... given that we have garbage collection, plenty of physical
memory, and tons of virtual memory on most computers these days, is it
really worth the effort? Only you can decide.
 
S

Samuel R. Neff

I wasn't aware that the Memento pattern can save memory. How does it
to that?

Thanks,

Sam


Well, there's one condition that must be met:
The interface for your classes if implemented using the memento
pattern should be identical to the interface if they were implemented
with plain old fields.

And memory and performance issues aside, there's one downside:
Added complexity.

For the memento pattern to be justified, your application would have to
be using a huge amount of objects that are immutable, and are large
enough in terms of memory footprint. The number and state of those
objects must also be known at design time.

If all of the above is met, then you should be able to save yourself
some memory by using the memento pattern.

But... given that we have garbage collection, plenty of physical
memory, and tons of virtual memory on most computers these days, is it
really worth the effort? Only you can decide.

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
K

Kevin Yu [MSFT]

Hi Sam,

I don't think Mohammad means that the memento pattern. I think he just
means that with the hardware and Garbage Collection today, we needn't worry
about the memento pattern who stores a huge amout of immutable objects.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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

Top