Observer Pattern in C#
-
quarta-feira, 15 de agosto de 2012 02:38
Hi,
I have started reading Head First Design Patterns. The language used in the book is Java.
I am now in the Observer pattern chapter, and I am now trying to implement it in C#. I read that we can use IObservable and IObserver interfaces but when I try to use the example in MSDN, I get the following errors:
Error 3 The type or namespace name 'IObserver' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\xxx\Local Settings\Application Data\Temporary Projects\WeatherStation\Program.cs 48 37 WeatherStation
Error 5 The type or namespace name 'IObservable' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\xxx\Local Settings\Application Data\Temporary Projects\WeatherStation\Program.cs 61 39 WeatherStation
I am using Visual Studio 2005
Todas as Respostas
-
quarta-feira, 15 de agosto de 2012 07:45
you will need to add mscorlib.dll into your reference, which you can get in the .Net component in your project(but I guess there are some issues in Visual Studio 2005 with this assembly)
http://msdn.microsoft.com/en-us/library/dd783449.aspx
regards
- Marcado como Resposta Bob ShenMicrosoft Contingent Staff, Moderator terça-feira, 28 de agosto de 2012 10:02
-
quarta-feira, 15 de agosto de 2012 13:21
C# and java has a few differences, so an easy implementation of the pattern would most likely look something like this:
http://blogs.msdn.com/b/bashmohandes/archive/2007/03/10/observer-pattern-in-c-events-delegates.aspx
- Marcado como Resposta Bob ShenMicrosoft Contingent Staff, Moderator terça-feira, 28 de agosto de 2012 10:02
-
quarta-feira, 15 de agosto de 2012 14:24
Hi cindyak;
The IObserver interfaces is not supported in Visual Studio 2005 and therefore can not be used. Check out Thomas post for a implementation that does not use IObserver interfaces.
Fernando (MCSD)
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Marcado como Resposta Bob ShenMicrosoft Contingent Staff, Moderator terça-feira, 28 de agosto de 2012 10:02

