Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Observer Pattern: Dangling References
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00354611
Message ID:
00355500
Views:
29
Ken,

The destruct order shouldn't matter. Do your observers also hold a reference to the subject? If so your subject should maybe broadcast a message to them letting them know it is going away and therefore no longer observable:
* subject.Destroy()
for i = 1 to alen( this.aObservers )
   if ( IsObject( this.aObservers[i] ) )
      this.aObservers[i].StopObserving( this ) && might need a parm if the observer 
                                                 && can observer multiple objects
      this.aObservers[i] = .null.
   endif
endfor

* observer.StopObserving( roSubject )
if ( IsObject( this.oSubject ) )
   this.oSubject.Detach( this )
endif
if ( IsObject( roSubject ) )
   roSubject.Detach( this )
endif
this.oSubject = .null.

*observer.Destroy()
this.StopObserving( .null. )
>I'd tried the detach method below in the subject object. I was calling the subject.detach from the observer.destroy. It seemed no matter what I did with the subject's zorder it always got destroyed first. I'm not using pemstatus() or getpem().
>
*subject.detach method
>lparameter cObserverName
>local cObserverName
>for x = 1 to alen(This.aObservers)
>	if this.aObservers(x).Name = cObserverName
>		this.aObservers(x) = .null.
>	endif
>next
>
As it stands, I've duplicated the above code (without the conditional) in a method called DetachAll, and I'm calling it from the form.destroy per Nancy's suggestion. It works, but seems to break from the pattern as defined by G&H.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform