• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Is it acceptable practice to use such method name in controller and service classes for REST?

 
Ranch Hand
Posts: 1115
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have a  REST controller with method name such as fetchUserDetails. Can I use the same name in the method of service class which actually does the task of fetching the user details  or should I have to use some other name?


If the controller class has method name such as fetchUserDetails which calls the service class method which actually does the task of fetching the user details, then can this method too be names fetchUserDetails or should I user some other name?

thanks
 
Ranch Hand
Posts: 85
2
Python Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:Suppose I have a  REST controller with method name such as fetchUserDetails. Can I use the same name in the method of service class which actually does the task of fetching the user details  or should I have to use some other name?


If the controller class has method name such as fetchUserDetails which calls the service class method which actually does the task of fetching the user details, then can this method too be names fetchUserDetails or should I user some other name?

thanks



You can use the same name, but rather use a different name as it will create confusion.
 
Monica Shiralkar
Ranch Hand
Posts: 1115
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the name in controller class is fetchUserDetails, what can be the name in service class?
 
M Khalid
Ranch Hand
Posts: 85
2
Python Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:If the name in controller class is fetchUserDetails, what can be the name in service class?


You can keep it as you wish "same or different". Eventually you have to autowire the service or invoke service class object and call the method of Service class.
 
Monica Shiralkar
Ranch Hand
Posts: 1115
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can keep it as you wish "same or different".



Yes, but is it acceptable coding practice to keep the same name?
 
M Khalid
Ranch Hand
Posts: 85
2
Python Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:

You can keep it as you wish "same or different".



Yes, but is it acceptable coding practice to keep the same name?



No
 
Monica Shiralkar
Ranch Hand
Posts: 1115
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is what the question is. If it is not acceptable practice to keep the same name the  what kind of name can be used for the service class method if the controller class method has been  named fetchUserDetails.?
 
M Khalid
Ranch Hand
Posts: 85
2
Python Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:Yes that is what the question is. If it is not acceptable practice to keep the same name the  what kind of name can be used for the service class method if the controller class method has been  named fetchUserDetails.?



"getUserDetails"
 
Saloon Keeper
Posts: 10302
217
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

M Khalid wrote:

Monica Shiralkar wrote:Yes, but is it acceptable coding practice to keep the same name?


No


Is this general consensus or your opinion? If the latter, then you probably shouldn't present it like it's consensus.

M Khalid wrote:"getUserDetails"


I actually find this much more confusing. You basically have two methods that do the same thing but you give them subtly different names? And how would it be confusing in the first place to have the controller and service methods have the same name?
 
Monica Shiralkar
Ranch Hand
Posts: 1115
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I actually find this much more confusing. You basically have two methods that do the same thing but you give them subtly different names? And how would it be confusing in the first place to have the controller and service methods have the same name?



Thanks. I always had that doubt that if I have to use a name such as getUserInfo in Controller then for the service class I have to think of some name such as fetchUserInfo just because I should be using a different name. So I think it should be fine to use the same name at both places.



 
Stephan van Hulst
Saloon Keeper
Posts: 10302
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I think so.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!