Download presentation
Presentation is loading. Please wait.
Published byJaylynn Harbottle Modified over 9 years ago
1
O RPHANS, A DOPTION, AND S URROGATES S INGLETONS Josh Mason June 1, 2009
2
A DOPTION AND O RPHAN Adoption Taken ownership of object Orphan Relinquish object What’s the purpose? Deciding where to put adoption/orphan functions Component? Leaf? Composite? Case by case basis.
3
S INGLETON Creational Pattern Restricts instantiation of a class to a single instance
4
U SES To implement other patterns Abstract Factory Builder Prototype Façade State Objects
5
S INGLETON - B ENEFITS Single Instance Controlled Access Reduced Namespace Lazy Initialization Easily extends to allow for a variable number of instances. Can assist in making thread safety simpler.
6
S INGLETON - E XAMPLES Traditional static MyClass* Instance(); Alternative 1 static MyClass* Instance(int i_id); static MyClass* Cleanup(int i_id); Alternative 2 static Create(int i_val, float i_val2); static MyClass* Instance(); static Cleanup();
7
S TINKLETON * - I SSUES Why not just use global variable? An anti-pattern? Creation Cleanup Tight coupling * Robert Penner
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.