C
C#3mo ago
azttor

Observer pattern and strategy pattern together?

I was reading chapter 2 in head first design patterns and the subject is a weather station and the observer has an update method that takes in the weather data from the weather station. Would it be ideal to be able to implement a strategy pattern for what the update method takes in?
3 Replies
azttor
azttorOP3mo ago
the observer then would be able to check the class instance type is of the correct strategy for it to proceed or would it just be better for Update() to just take in a generic<T>?
SleepWellPupper
SleepWellPupper3mo ago
It would be the strategies responsibility to determine the reaction, not the publishers. That's kind of the point. You want to avoid type checks like that if you want to scale your class system because it couples you tightly to the types you check for and leaves you vulnerable to not supporting new ones correctly (because you forgot to check for them). But more details would help in a more informed reply. Maybe share some sample $code
MODiX
MODiX3mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Want results from more Discord servers?
Add your server