This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to Design This

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a singleton public class encapsulating, say, all the global methods for some speciifc math calculation. An issue with the class is that, by the very nature of the use case, there are a lots of String constants & the ways to manipulate them that would keep changing. So every 1 or 2 weeks I need to rewrite the class for new version of the constants . But this is a tedious and error prone task since the class is getting very large and I need to scan through the whole class to identify method by method which constants need changing.

I am thinking of a better way to design my class. One design I am thinking of is to extract all those String that I know is keep changing into another INNER class and expose getter to return the Strings and methods showing the new way to manipulate the String. I choose to use inner class is that those String constants are private to my singleton class i.e. no one else should be able to see them directly. But I need to make sure every new version conform to the same method signature, so the inner class must implement an interface so that when I provide my new version of the inner class of getter's I am sure I have provided all methods required by the interface.

But the problem with my design is that if my inner class implements an interface, they methods have to be public. But I don't want to expose them to everybody as they clearly are private to my singleton public class. This singleton public class is the real one to be a public class and be called by other.

So is there a better way to design my class so that I can easily inject new versions of a class without having the class made public. Just like dependency injection in Spring framework but I dont want the injected object be public class.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Alec

Try to use HashMap in the class to remember your method name.

if not clear share the small code and I will rewrite it for you

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic