• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface design issue  RSS feed

 
Tom Hartwell
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it bad, possibly bug-inducing, to have a class implement an interface and also take that interface in as a constructor argument. Here's my design issue:

I'm programming a web app that has an extensive service layer. To provide layering, I've created a ServiceLayerContext class that can take in an HttpRequest or several other objects to properly initialize. Service classes take this context in to properly initialize themselves. Here's a case:

1) HttpServiceLayerContext implements ServiceLayerContext
2) MyService extends BaseService

3) MyService(ServiceLayerContext slc) {
super(slc);
}

If a service method needs to call another service constructor, I thought it would be good to be able to do something like this.

4) MyOtherService extends BaseService...

and in MyService

void aMethod() {
MyOtherService otherService = new MyOtherService(this);
}

In order to do this I wanted the BaseService to implement a similar interface as the ServiceLayerContext classes. It seems weird, but somewhat logical to do:

BaseService implements ServiceLayerContext

It's weird b/c now any service that extends BaseService will be implementing an interface that is also used in it's constructor. Shortly after doing this I ran into a problem, but have no idea if it's related to this design change:

java.lang.NoSuchMethodError: com.company.services.MyService.<init>(Lcom/sys/uswdss/services/HttpServiceLayerContext V

Ideas?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!