User.java 768 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package observerPattern.observer.impl;
  2. import observerPattern.observer.Observer;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. public class User implements Observer {
  6. private static final Logger log = LoggerFactory.getLogger(User.class);
  7. String name;
  8. Integer age;
  9. public User(String name, Integer age) {
  10. this.name = name;
  11. this.age = age;
  12. }
  13. public String getName() {
  14. return name;
  15. }
  16. public void setName(String name) {
  17. this.name = name;
  18. }
  19. public Integer getAge() {
  20. return age;
  21. }
  22. public void setAge(Integer age) {
  23. this.age = age;
  24. }
  25. @Override
  26. public void update(String message) {
  27. log.info("{}收到了消息: {}", name, message);
  28. }
  29. }