Solved

Dependency injection names?

Posted on 2014-12-02
1
44 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
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now