We don't have any frameworj like Spring where we can inject dependencies using annotations or xml file. We have handler classes, service classes and dao classes.
Handler classes access service which perform business logic to get the data to be persisted into the db using dao layer.
Now I have seen that in our project we are adding the dao dependencies in the Service class by declaring them as shown below:
TestService.java
Class ServiceImpl{
private static final TestAccessor accessor = TestAcceessor.Instance;
}
Here the TestAcceessor
is an enum
and is made Singleton.
My questions are as follows:
Is implementing the Accessors singleton using enum and then declaring them as shown above(
static final
) means there is no tight coupling between our project's Service class and DAO class? IMO there is no tight coupling as we are just accessing the enum constant and any change to DAO enum doesn't make us change the service class.Since we are accessing Service classes from Handler classes, how can we inject DAO dependencies if required into service(We don't use Spring) class? IMO we don't want to do that from Handler as that would expose our DAO classes to Handler and thus make them insecure.
1.
Is implementing the Accessors singleton using enum and then declaring them as shown above(
static final
) means there is no tight coupling between our project'sService
class andDAO
class?
IMO there is no tight coupling as we are just accessing the enum constant and any change to DAO
enum doesn't make us change the service class.
2.
Since we are accessing
Service
classes fromHandler
classes, how can we inject DAO dependencies if required into service(We don't use Spring) class?
IMO we don't want to do that from Handler as that would expose our DAO
classes to Handler
and thus make them insecure.