Case: you are using decoration design pattern
You have Window object as base, FrameWindow derived as decorator from Window, and ScrollFrameWindow derived as decorator from FrameWindow.
...you bump into situation you have Window *w = new ScrollFrameWindow(new FrameWindow(new Window)); ... And after while, you don't need decorator ScrollFrameWindow, but you still need decorator FrameWimdow for your Window.
Is this best solution to strip down to FrameWimdow: 1. Make sure you use only dynamic allocated object as properties in your decorator 2. Make in every decorator virtual function eraseMe, for deleting dynamic allocated object, that are bound to target decorator 2.1. Call eraseMe 3. Cast your pointer to next decorator in your chain 4. Make flag in target decorator that it is deleted
What about virtual function, do you need then everywhere in code do check if this pointer refer to object with no flag "deleted"?
If this is best solution, is casting pointer on section 3) better to do with template, or is it too-broad question?
I would like someone do formatting on this question.
Aucun commentaire:
Enregistrer un commentaire