0

I have a trait that representing some module that exposes some public method (think of a service):

trait X { 
  def exposeMe: AService = ...
  def keepMeHidden: BService = ...
}

Then, I have a Y module that requires services from X. Clients of Y also need one service from X. But I don't want them to depend on whole X, just on this one service. I would like to like "export" that one service to be public.

trait Y { this: X => 
  def exposeMe2: AService = exposeMe
}

This works, but is there a way to keep the method name the same?

Łukasz
  • 8,555
  • 2
  • 28
  • 51

1 Answers1

2

Short answer:

trait X { 
  def exposeMe: Int = 12
  def keepMeHidden: Int = 41
}

trait XComponent {
  def x: X
}

trait Y { this: XComponent => 
  def exposeMe: Int = x.exposeMe
}

Update after question edition.

Problem is that you baked half of cake and then want to extract a layer from this complex component. Right way is to require what you really need:

trait Y { this: AServiceComp => 
  def exposeMe: AService = aService.exposeMe
}

Where AServiceComp implementation could be made with single AService implementation or using new XImpl.exposeMe (imho the last is bizarre).

Zernike
  • 1,758
  • 1
  • 16
  • 26
  • I updated my question. Those methods weren't actual methods but getters for services. And X is already a component/module. – Łukasz May 08 '17 at 09:08