I am using typescript and angular.
I have 2 service that are very similar, but the property are different :
synchronizedMaps: Map<string, Map<string, MapSynchSettings>> = new Map<string, Map<string, MapSynchSettings>>();
groupDispatchers: Map<string, Subject<SynchMapGroupSubject>> = new Map<string, Subject<SynchMapGroupSubject>> ();
mapDispatchers: Map<string, Subject<SynchMapSubject>> = new Map<string, Subject<SynchMapSubject>> ();
public createNewSynchGroup(id?: string): Observable<SynchMapGroupSubject> {
this.synchronizedMaps.set(id, new Map<string, MapSynchSettings>());
this.groupDispatchers.set(id, new Subject<SynchMapGroupSubject>());
this.mapDispatchers.set(id, new Subject<SynchMapSubject>());
return this.groupDispatchers.get(id).asObservable();
}
and
synchronizedDrawer: Map<string, Map<string, SynchWaypointDrawerSettings>> = new Map<string, Map<string, SynchWaypointDrawerSettings>>();
groupDispatchers: Map<string, Subject<SynchWaypointDrawerGroupSubject>> = new Map<string, Subject<SynchWaypointDrawerGroupSubject>> ();
waypointDispatchers: Map<string, Subject<SynchWaypointSubject>> = new Map<string, Subject<SynchWaypointSubject>> ();
constructor() { }
public createNewSynchGroup(id?: string): Observable<SynchWaypointDrawerGroupSubject> {
this.synchronizedDrawer.set(id, new Map<string, SynchWaypointDrawerSettings>());
this.groupDispatchers.set(id, new Subject<SynchWaypointDrawerGroupSubject>());
this.waypointDispatchers.set(id, new Subject<SynchWaypointSubject>());
return this.groupDispatchers.get(id).asObservable();
}
The property type, and the method returned value change, but the method implementation and logic of those 2 service are exactly the same.
I wanted to know if there is a method to merge those 2 service into a single one, or make a parent class that I can extend with just the variable types but all the name and logic will be kept the same.
thanks