Win a copy of Microservices Testing (Live Project) this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Interface implementation dependency resolver

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

There are some Interfaces and implementation classes.
Some classes would be having dependency on the interface implementation,
If it would have been spring Framework, It will find the interface implementation and assigns implementation class to it.

In the following Spring will find Ishape implementation and assigns it to IShape.


Without Spring,

I need to declare like,


But, the above code is having actual implementation this.shape = new ShapeImpl(); class with-in the code. Is there a way to do without spring using plain java.

Something,like this.shape = createObject(IShape.class) . But,haven't got good Idea about implementation of createObject.

Any help would be appreciated.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, use a factory, or create an object using forName()/newInstance(), or...
 
Ramya Chowdary
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
createObject need to find the implementation class of the interface and then intailize.
Intailizing from classname is fine,But I can't able to find API for finding interface implementaiton class

Can you elaborate more on factory?

Thanks for reply,I would be searching on factory pattern.
reply
    Bookmark Topic Watch Topic
  • New Topic