1 / 7

Orphans, Adoption, and Surrogates Singletons

Orphans, Adoption, and Surrogates Singletons. Josh Mason June 1, 2009. Adoption and Orphan. 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. Singleton.

scout
Download Presentation

Orphans, Adoption, and Surrogates Singletons

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Orphans, Adoption, and SurrogatesSingletons Josh Mason June 1, 2009

  2. Adoption and Orphan • 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. Singleton • Creational Pattern • Restricts instantiation of a class to a single instance

  4. Uses • To implement other patterns • Abstract Factory • Builder • Prototype • Façade • State Objects

  5. Singleton - Benefits • 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. Singleton - Examples • Traditional • staticMyClass* Instance(); • Alternative 1 • staticMyClass* Instance(inti_id); • static MyClass* Cleanup(inti_id); • Alternative 2 • staticCreate(inti_val, float i_val2); • staticMyClass* Instance(); • staticCleanup();

  7. Stinkleton* - Issues • Why not just use global variable? • An anti-pattern? • Creation • Cleanup • Tight coupling * Robert Penner

More Related