Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Observer Design Pattern--is my use-case good for ita good use case for ?  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a use-case where as soon as my API receive a request, then i make make a call to some remote server, fetch the data, run my processing on that data and populate a response object. Now i need to do two things: 1) return this response object to the caller of my API which completes this flow in the same thread, 2) Also start a[b] Async thread to update this response object data's in Stringify manner to a cache . This second flow is fire and forget style. Here I am planning to use observer pattern in second flow ( the Async one).So that means as soon the response object is formed, it will call a subject class's setValue(..) method which will call its observer and in the observer's update() method i will span a thread which will update the cache.
Someone was saying using observer here i am increasing the time of processing here but i feel its provides loose coupling and extandability. Lets me know your thoughts so i can take it further.
 
Sheriff
Posts: 13155
219
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My main considerations for design, in order of highest importance (1=most important):
1. Simplicity (meets the current requirements with least complexity)
2. Easy to understand
3. Easy to extend (loose coupling, cohesive, etc.)
4. Secure
5. Performant (see Three Rules of Optimization)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!