Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

General data fetching best practice

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our application has 2 interfaces, one is web and the other is mobile. My question is, do you guys use single( read same) service layer method for specific functionality to serve web and mobile interface? Or have separate methods?

For example, get/EditUserDetails(userId). On web interface, you want to display all user related details whereas on mobile you only want to fetch some of the details. Since the amount of data being fetched is different, do you write separate method for each or only one method where you fetch everything? There is tread-off between # of LOC and amount of data being fetched.

Thank you for your time.
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presentation layer should always be separate from the data layer. There is no reason the data layer needs to be duplicated to support more than one presentation layer. Ideally, your data layer should be Service-based, which is composable to form new and unique uses. See Service Oriented Architecture / Composable Services.
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger Sterling wrote:Presentation layer should always be separate from the data layer. There is no reason the data layer needs to be duplicated to support more than one presentation layer. Ideally, your data layer should be Service-based, which is composable to form new and unique uses. See Service Oriented Architecture / Composable Services.


Should I have two methods at service layer? One that feeds web app,and another which operates on the output of first method and strip it down and return the result to mobile app. Is this right?
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saurabh Pillai wrote:
Roger Sterling wrote:Presentation layer should always be separate from the data layer. There is no reason the data layer needs to be duplicated to support more than one presentation layer. Ideally, your data layer should be Service-based, which is composable to form new and unique uses. See Service Oriented Architecture / Composable Services.


Should I have two methods at service layer? One that feeds web app,and another which operates on the output of first method and strip it down and return the result to mobile app. Is this right?


Why do you need two ? Whats wrong with using one ? Two presentation layers making the same call to the one data layer. Did you look at the article I posted earlier in this thread ? About Service Composability?
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger Sterling wrote:Why do you need two ? Whats wrong with using one ? Two presentation layers making the same call to the one data layer. Did you look at the article I posted earlier in this thread ? About Service Composability?


Web app needs more user related data whereas mobile app needs lesser user related data. That's why I mentioned about 2 methods. Because if I use the same method that I am using for web app then I would transfer unnecessary data to mobile app. They both accept different amount of user related data. For example, Web app needs 30 attributes of user whereas mobile app only need 10 attributes. I hope I am clear enough.

And yes I read the article.

Thank you
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are talking about filtering , which could be done via a view. The callable interface could support a parameter that selects various available views. One view brings back a certain set of data whereas a second view brings back a more constrained (ie limited) set of data. Thanks for reading the article.
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger Sterling wrote:You are talking about filtering , which could be done via a view. The callable interface could support a parameter that selects various available views. One view brings back a certain set of data whereas a second view brings back a more constrained (ie limited) set of data. Thanks for reading the article.


Why I should I fetch some data from DB that I am certainly going to discard at view layer? This is what bothering me. If I understood you correctly, I will use single method that serves both views, web app and mobile app. So when mobile app requests it, I fetch the data then strip it down to what is necessary and then send it to mobile app. Why should not I fetch data that is necessary for ONLY mobile app? Why should not I write 2 methods one for web app (fetches 30 attributes) and one for mobile app(fetches 10 attributes)? This way it will reduce load on DB since for mobile request, it only fetches 10 fields as opposed to fetching 30 fields for web app.

PS :- Not trying to argue but just want to be 100% clear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic