jeudi 27 février 2020

Providing OSGi Service Without Implementing Interface

Sample 1

@Component(policy = ConfigurationPolicy.OPTIONAL, immediate = false)
public class ServiceImpl implement Service {

  @Override
  public void foo() {

  } 

  ...
}

Sample 2

@Component(policy = ConfigurationPolicy.OPTIONAL, immediate = false)
public class Service {

  public void foo() {
  } 
  ...
}

I have a component which consists some methods. I want to provide a ServiceImpl class which implement Service interface as a OSGi service(in sample 1). However, Service interface is implemented by single class. According to YAGNI design principle, Creating interface for only one class is unneeded. Instead of doing this, creating class which has methods is preferable(in sample 2). If I choose sample one, I will ignore some convensions including YAGNI and class naming(not impl suffix but specific name). If I choose sample 2, It won't suitable for OSGi environment. I am confused what I should do.

Aucun commentaire:

Enregistrer un commentaire