50 likes | 216 Views
Week 4, Day 1: Singleton(s?). Singleton leftover Why singletons? How to make lazy initialization work multi-threaded? Observers Why observers? Class structure for observers Lab Wednesday: Cumulative Quiz. Why Singletons?. Single interface to another program Website Database
E N D
Week 4, Day 1:Singleton(s?) • Singleton leftover • Why singletons? • How to make lazy initialization work multi-threaded? • Observers • Why observers? • Class structure for observers Lab Wednesday:Cumulative Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder
Why Singletons? • Single interface to another program • Website • Database • Data logging • Any large object that you want to be static but intialize later SE-2811 Dr. Mark L. Hornick
Fixing the Locking Problem • In-class example SE-2811 Dr. Mark L. Hornick
Why Observer? • Events • GUI • Very good general structure for • Decreasing coupling • Increasing readability SE-2811 Dr. Mark L. Hornick
Basic class relationships Subject ------------------------------ attach():voiddetach():voidnotifyObservers():void Observer---------------- update(???):void -observers 1..* SubjectClass ObserverClass1 ObserverClass2