Guest User

Untitled

a guest
Oct 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. /** Wrapper for Company class */
  2. class CompanyWrapper(company: Company) {
  3. // methods that we want to "add"/patch to company
  4. def getRank(): Int = {
  5. company.source match {
  6. case BSCAN => 120983019283
  7. case SDAWN => 190238109
  8. }
  9. }
  10.  
  11. def getNumberOfIndustries: Int = {...}
  12. def fancyMethod: Int = {...}
  13. }
  14.  
  15. // add an implicit conversion from Company to CompanyWrapper
  16. // to locations where you want to have the extra methods "visible"
  17. class UnifiedCompanySearchClient {
  18. // source of magic :)
  19. implicit def wrapCompany(company: Company) = new CompanyWrapper(company)
  20.  
  21. // we can now use the extra methods we created
  22. val company = new Company(...)
  23. company.getRank() // should return rank
  24. company.getNumberOfIndustries()
  25.  
  26. }
Add Comment
Please, Sign In to add comment