java - How to implement a class that has multuple instances, none of which can be equal -


my implementation consist of java class representing source repository. want implementation such there 1 object per source repository. if multiple instantiations done per source repository, want unique object representing source repository returned.

are there known patterns/practices achieve this?

note : if need unique object have using singleton pattern. in scenario there can multiple objects no 2 objects representing same source repository.

  • save static map repository=>instance.
  • make constructors private
  • write static method instance desired repository parameter
  • get instance map or if not present, create it, put map , return it

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -