• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Class without state vs static methods

 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a requirement where we call another system and have to prepare the corresponding request from our request.

Let us call classes - OurRequest, DownstreamCallRequest, DownstreamRequestAdapter

DownstreadmRequestAdapter has a method : public DownstreamRequest adapt(OurRequest ourRequest) signature.

I don't have any state variables in the Adapter class.

What will be a better OO design?
1. To have the adapter class with 'static' method - public static DownstreamRequest adapt(OurRequest ourRequest)
2. To have the adapter class with an instance adapt method but no state variables in the class

Appreciate your opinion on this.

Thanks
Maulin
 
Sheriff
Posts: 17702
301
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Concerns with static methods are different from concerns with static variables so there's really no comparison to be made here; it's apples vs oranges in this case, IMO, as long as no state is kept either way. I imagine you'd end up using a single instance to handle all requests anyway so that's essentially the same as having the method as a class member rather than an instance member. The only real difference you'll have is whether you're calling the method via an instance or via the class itself, which to me seems like it's pretty much the same difference in this case.
 
Junilu Lacar
Sheriff
Posts: 17702
301
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only other consideration would be if you were using the Spring Framework, in which case the second option would be a more natural choice. You still essentially have a singleton though.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response. It clarifies things.
 
Your mother was a hamster and your father was a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic