You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Som Lima <so...@gmail.com> on 2021/08/06 20:02:25 UTC

Dependency Injection as a common Interface not requiring suffix "impl"

Hi,
What do you think of my explanation below ?

Dependency Injection - Common Interface

The purpose of Dependecy Injection DI is to extract Common
Interfaces. common Interface contains functions which are common to two or
more objects. For example Engine is common to Combustion Engine , Electric
Engine , Hybrid Engine Rocket Engine , Submarine Engine   , as legs are a
feature common to cats , dogs, lions , birds , feathers are common to
eagles , chickens etc.

I think if there is a clash of name and one has to suffix the
implementation class name with impl then one is not really using the
Interface as a common interface. Common Interface is of course similar to
using a library but not quite the same because Common Interface is part of
the skeletal design of the implementation class hierarchy.

In Java multiple "implements" of Interfaces are possible unlike extend
which can only do one of. This makes perfect sense because complete objects
can have multiple interfaces , at the same time each common interface is
unrelated to each other. For example a cat or a dog will have common
Interfaces such as legs and sound. Both legs and sounds are unrelated to
each other therefore are encapsulated in their own classes. Both are common
features of cats and dogs , monkeys etc.

 therefore classes such as cats and dogs require multiple "implements" of
common Interfaces to create whole objects of cat, dog, monkey objects.

So if one looks upon Dependency Injection as way of extracting common
Interfaces for inheritance and to reduce reduce repeated code, adding
suffix "impl" to fix name clash between implementation class name and
interface class name should be unnecessary.