Solved

Dependency injection names?

Posted on 2014-12-02
1
55 Views
Last Modified: 2015-02-23
I want to create my own dependency injection in my Java code and wonder what the names would be for different parts.

Lets say I have an Interface X.
It is being implemented by my class Y w.   ich is ijected with my class Z at creation time. What would sensible names be then?
FooBarInterface
FooBarService
FooBarHandler

Any better ideas?
0
Comment
Question by:mdoland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 40477498
You haven't given enough information to begin to advise on good names for YOUR situation. That is the issue here, it is totally dependant on YOUR particular application/design.

But maybe giving you an example of a more real-world case (rather than X, Y, Z and FooBar...). So say you have a need to get products from an inventory database. At a really high level you might have a "ProductService" class and it needs to be injected with an instance of the "ProductDataSource" interface. Therefore, you might implement an "OracleProductDataSource" class that implements the ProductDataSource interface by accessing an Oracle database to actually fetch the required information. In production, you can inject an instance of that class into your ProductService. And then in testing you could create a "TestProductDataSource" class that just provides some test data to assist in testing your ProductService.

This is still somewhat theoretical and depending on the application you may even break this up into additional levels, but it is just an example for possible naming conventions and the one that I try and use. The main theme from the above, is that I usually DON'T have Interface in the name of my interfaces, and classes that implement my interfaces "prepend" some descriptive word(s) to the front of the interface name. Just one more quick example to give you the idea... you might have an EventProducer interface and implementations of it called KeyboardEventProducer and MouseEventProducer, etc.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 74
hibernate example using maven 12 82
spring jars download 1 53
Facing this issue for maven proxy setting 2 27
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question