• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

OOP/ Rest API design

 
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Would this be good design for an API that tries to get a list of items to search (in a file perhaps) from the input (JSON) and returns the number of occurences of each?

A controller class with a method:

A service class that does this:

A model that stores the input like this:

Assuming there would be some content in which to search - I am thinking that the service class can do the searching (maybe use a map to store count for each word) and return a map.

Please comment about both OO desjgn and Rest service design.

Input might be something like this:



Output:

 
Raja Avrv
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, to do the actual computing of finding the frequency of the given words in a file, could I split the file into Strings, then loop through using a map? But I only want to find count for the given words, not all words.

And, how do I split into strings ignoring all the characters like ,. etc. There could be any character like this and I wouldn't know, so what would be the best way?
 
Marshal
Posts: 69411
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please explain a bit more about your design. But “search” isn't a good name for a method which doesn't search for anything. It counts things. In which case, why does it return String rather than a number? Have you got any utility classes? Don't know anything about Rest. Sorry.
I presume you have seen the example in the Java™ Tutorials which does the counting rather like the way you described it. What about a matches() method to find words. You can use a regex for letters only. But beware of words like self‑confident and Raja's that you don't mistakenly divide such words into two.
 
Raja Avrv
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I don't know if I necessarily want to split the sentence or not. As long as I can find a way to just find the given search strings in the sentence, it shouldn't matter how it's done. What would be the best way to do this? Would I still need to use regex?
 
Raja Avrv
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Please explain a bit more about your design. But “search” isn't a good name for a method which doesn't search for anything. It counts things. In which case, why does it return String rather than a number? Have you got any utility classes? Don't know anything about Rest. Sorry.
I presume you have seen the example in the Java™ Tutorials which does the counting rather like the way you described it. What about a matches() method to find words. You can use a regex for letters only. But beware of words like self‑confident and Raja's that you don't mistakenly divide such words into two.



Thank you. I'll rename it to something like findFrequency. I only made it a String for now to test if the Rest Api returned something, will probably change it later to return a Response object.

I don't have any utility classes; I thought I could have the method in the service class do the work. Would that be Ok?

And how do I make sure that I don't mistakenly divide words?
 
Raja Avrv
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Map example has the contents in a map, but my content is a complete sentence or say a paragraph.
 
Marshal
Posts: 15630
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to read up on how to properly design a RESTful API for this kind of task. Here's one article that you can start with: https://medium.com/hashmapinc/rest-good-practices-for-api-design-881439796dc9
 
no wonder he is so sad, he hasn't seen this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic