Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Wrapper for Company class */
- class CompanyWrapper(company: Company) {
- // methods that we want to "add"/patch to company
- def getRank(): Int = {
- company.source match {
- case BSCAN => 120983019283
- case SDAWN => 190238109
- }
- }
- def getNumberOfIndustries: Int = {...}
- def fancyMethod: Int = {...}
- }
- // add an implicit conversion from Company to CompanyWrapper
- // to locations where you want to have the extra methods "visible"
- class UnifiedCompanySearchClient {
- // source of magic :)
- implicit def wrapCompany(company: Company) = new CompanyWrapper(company)
- // we can now use the extra methods we created
- val company = new Company(...)
- company.getRank() // should return rank
- company.getNumberOfIndustries()
- }
Add Comment
Please, Sign In to add comment