Seeking out a design pattern for the following scenario:
IApp.ts
export interface IApp {
platform: PlatformEnum;
version: string;
islive: boolean;
title: string;
iconurl: string;
}
IAppleApp.ts
export interface IAppleApp extends IApp {
buildversion: string;
versionstatus: string;
sku: boolean;
category: string;
accountid: string;
}
IAndroidApp.ts
export interface IAndroidApp extends IApp {
versioncodes: string;
track: string;
rolloutpercentage: boolean;
acccountname: string;
}
Basic models representing incoming data.
A service makes API calls and fetches data as IApp
.
apps.service.ts
appVersion: IApp;
appiOSVersion: IAppleApp;
appAndroidVersion: IAndroidApp;
if (this.appVersion.platform === PlatformEnum.ios) {
this.appiOSVersion = this.appVersion as IAppleApp;
} else if (this.appVersion.platorm === PlatformEnum.android) {
this.appAndroidVersion = this.appVersion as IAndroidApp;
}
Utilizing appsService.appiOSVersion
in the Apple
component, and appsService.appAndroidVersion
in the Android
component with separate logic for each. Attempted to use appsService.appVersion
in both components, but lacking platform-specific properties forced the use of two variables.
Question: Can appsService.appVersion
be reused in both Apple
and Android
components? Need this variable for state management within apps.service.ts
. Using multiple variables isn't unreasonable, correct?
If unclear, please request more details.
Thank you!