• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

How to Design This

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic