Search This Blog

Friday, May 7, 2010

Observer Pattern

Java program name: observer/WeatherStation
Implemented as DoFactory.HeadFirst.Observer.WeatherStation
This example uses a .NET 2.0 generic List -- List in C# and List(Of T) in VB.NET.
Page 67: Reworking the Weather Station with built-in support
Java program name: observer/WeatherStationObservable
Implemented as DoFactory.HeadFirst.Observer.WeatherStationObservable
.NET does not support the Observer/Observable built-in types so this example uses two hand-coded types: the IObserver interface and the Observable base class. However, a better way to implement the Observer pattern in .NET would be to use .NET multicast delegates as demonstrated in the next example. This code sample uses a .NET 2.0 generic List -- List in C# and List(Of T) in VB.NET.
Page 72: Other places you’ll find the Observer Pattern
Java program name: observer/Swing
Implemented as DoFactory.HeadFirst.Observer.DotNet
Copyright © 2006, Data & Object Factory. All rights reserved. Page 4 of 21
Design Pattern Framework™ 2.0
.NET does not support Swing, therefore this example has been implemented as a console application. In .NET the Observer Pattern is implemented very elegantly as multicast delegates which is demonstrated in this example. To keep the learning experience as close to the original Java code, no .NET 2.0 generic delegates were used. If you’d like to see generic delegates in action the please refer to the .NET optimized example in the Gang of Four Observer pattern.
Copyright

No comments:

Post a Comment