• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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
 
Marshal
Posts: 17013
298
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
Marshal
Posts: 17013
298
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.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic