Skip to main content
Code Review

Return to Question

edited tags; edited title
Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

The Observer design pattern in Python in a more pythonic way (plus, with unit testing best practices)tests

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I'm continuing to work on the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Code review for the Strategy pattern in Chapter 1 is here here with helpful explanations from the community.

I'm continuing to work on the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Code review for the Strategy pattern in Chapter 1 is here with helpful explanations from the community.

I'm continuing to work on the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Code review for the Strategy pattern in Chapter 1 is here with helpful explanations from the community.

add unit-testing tag
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419

I've tried to implement the Observer design pattern from chapter 2 below in Python. In the book all the examples are in Java. I'm sure there are more pythonicidiomatic Python things that I can do to this code. In the first example in this chapter we implement the Subject so that it pushes data out to the individual observers. In my code I wanted the Subject to notify the observers that new data was available, and have the observers pull only the data that each individual observer was interested in. I also tried to unit test instead of just printing output.

I've tried to implement the Observer design pattern from chapter 2 below in Python. In the book all the examples are in Java. I'm sure there are more pythonic things that I can do to this code. In the first example in this chapter we implement the Subject so that it pushes data out to the individual observers. In my code I wanted the Subject to notify the observers that new data was available, and have the observers pull only the data that each individual observer was interested in. I also tried to unit test instead of just printing output.

I've tried to implement the Observer design pattern from chapter 2 below in Python. In the book all the examples are in Java. I'm sure there are more idiomatic Python things that I can do to this code. In the first example in this chapter we implement the Subject so that it pushes data out to the individual observers. In my code I wanted the Subject to notify the observers that new data was available, and have the observers pull only the data that each individual observer was interested in. I also tried to unit test instead of just printing output.

Tweeted twitter.com/#!/StackCodeReview/status/295392697177473024
edited title
Link
PythonJin
  • 505
  • 2
  • 6
  • 10
Loading
Source Link
PythonJin
  • 505
  • 2
  • 6
  • 10
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /