Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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: 15779
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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)
 
    Bookmark Topic Watch Topic
  • New Topic