Wibowit
Wibowit

Reputation: 371

Which design patterns allows managing state of involved objects/ holding (lazy) (im)mutable state, inspect and modify object passed/ returned etc

Consider two problems:

  1. We have a wrapper that detects if the wrapped object started a transaction, keeps the transaction number and makes it available to users of wrapper through a method. Can it be called a facade, assuming it simplifies interface of course?

  2. There is a communication layer which provides high-level interface for low-level operations required to execute functions on attached device (these involves pushing bytes through socket and parsing the answers). Some of the answers contains a special "prompt number" which is required for some other queries. Communication layer detects answers which contains a prompt number and stores that number in a special holder which is available to caller. Could that be called a facade?

Overall those questions are related to a more general question: Which design patterns allows to store or manage mutable or immutable state and/ or inspect the objects that are passed to wrapped objects or returned from them.

Upvotes: 2

Views: 969

Answers (1)

Martin
Martin

Reputation: 4862

Take a look at the Observer Pattern http://en.wikipedia.org/wiki/Observer_pattern The State pattern could be of use as well: http://en.wikipedia.org/wiki/State_pattern and perhaps also Memento http://en.wikipedia.org/wiki/Memento_pattern depending on what you want to accomplish.

For the Observer look at boost signals and slots or at qt signals and slots for some neat implementation.

Upvotes: 1

Related Questions