• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • 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
 
Sheriff
Posts: 17644
300
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: 17644
300
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic