5

I have a dynamic form component that receive many services using angular DI system:

export class CityFormComponent<DataModel> extends BaseForm<DataModel> 
implements OnInit {

constructor(
    protected appConfig: AppConfig, 
    protected httpService: CityService,
    protected snackBar: MatSnackBar,
    protected componentFactoryResolver: ComponentFactoryResolver,
    private  cdr: ChangeDetectorRef,
    protected route: ActivatedRoute,
    protected router: Router) { 
          super(appConfig, httpService, snackBar, componentFactoryResolver,              route, router);
}

Is it a good practice to encapsulate all of the services except httpService in a wrapper facade service and then define methods that the form component needs and my base form class use those methods?

I have about 50 forms in my app and i want to sure that in the future when i want to add another service in my base form class,I don't have to change all the child class constructors and just add a method in my base class from facade service and then call facade service method to use added service so rest of my child form classes being unchanged.

export class FacadeService{

constructor(private appConfig: AppConfig, 
    private snackBar: MatSnackBar,
    private componentFactoryResolver: ComponentFactoryResolver,
    private  cdr: ChangeDetectorRef,
    private route: ActivatedRoute,
    private router: Router){
}

showSnackBar(){}

getRouteData(){}

navigate(){}

detectChanges(){}

getConfig(){}

resolveComponentFactory(){}

}

Base form class after changes look like this:

export abstract class BaseForm<DataModel> implements OnInit, AfterViewInit, OnDestroy {

 constructor(
    protected httpService: BaseService,protected facadeSerivce: FacadeService) {
}

}

Child form class:

export class CityFormComponent<DataModel> extends BaseForm<DataModel> 
implements OnInit, AfterViewInit, OnDestroy {

constructor(protected httpService: BaseService,protected facadeSerivce: FacadeService) { 
          super(httpService, facadeSerivce);
}
}
HDM91
  • 1,318
  • 9
  • 16
  • 7
    `I have about 50 forms in my app and i want to sure that in the future when i want to add another service in my base form class,I don't have to change all the child class constructors and just add a method in my base class from facade service and call facade service method to use added service so rest of my child form classes being unchanged.` -- That's all the justification you need. – Robert Harvey Feb 19 '19 at 19:22

0 Answers0