I'm currently working with TypeScript and Angular.
I have two services that are quite similar, but they have different properties:
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();
}
Although the property types and returned method values differ, the logic and implementation of these two services are identical.
I am exploring ways to potentially merge these two services into one or create a parent class that I can extend with only variable type changes while keeping all the logic and naming conventions consistent.
Thank you.