interface IUtilService {
name: string;
getName: Function;
}
class Service {
private utilService;
constructor(utilService: IUtilService) {
this.utilService = utilService;
}
getUtilService() {
return this.utilService.getName();
}
}
class A implements IUtilService {
name = "A Name";
getName() {
console.log(
this.name);
}
}
class B implements IUtilService {
name = "B Name";
getName() {
console.log(
this.name);
}
}
const s = new Service(new A());
const s2 = new Service(new B());