31
左のボックスの続き
index.ts (エントリーポイント)
export abstract class InsuranceAndInspection {
protected email : string
protected expire_date: string
protected notify_timing: string
constructor(email: string, expire_date: string, notify_timing: string) {
this.email = email
this.expire_date = expire_date
this.notify_timing = notify_timing
}
notify(): void {
this.sendEmail(this.email, '通知処理')
this.setNextNotifyTiming()
}
isNotifyTiming(): boolean {
const currentDate = this.formatDate(new Date());
return currentDate == this.notify_timing
}
abstract setNextNotifyTiming(): void
// sendEmail(),calculateDateBefore(),formatDate()は省略
}
export abstract class Insurance extends InsuranceAndInspection {
protected emergency_contact: string
constructor(email: string, expire_date: string, notify_timing: string,
emergency_contact: string) {
super(email, expire_date, notify_timing)
this.emergency_contact = emergency_contact
}
getEmergencyContact(): string {
return this.emergency_contact
}
}
export abstract class Insurance extends InsuranceAndInspection {
protected emergency_contact: string
constructor(email: string, expire_date: string, notify_timing: string, emergency_contact:
string) {
super(email, expire_date, notify_timing)
this.emergency_contact = emergency_contact
}
getEmergencyContact(): string {
return this.emergency_contact
}
}
export abstract class Inspection extends InsuranceAndInspection {
}
export class CarInspection extends Inspection {
setNextNotifyTiming(): void {
// expire_dateの1ヶ月前、3か月前、半年前に次の通知タイミングをセット
const today = new Date();
const one_month_before = this.calculateDateBefore(1);
const three_months_before = this.calculateDateBefore(3);
const six_months_before = this.calculateDateBefore(6);
if (today < six_months_before) {
console.log(‘今日は6か月前以前です’);
this.notify_timing = this.formatDate(six_months_before);
} // 以下、1ヶ月前、3か月前に次の通知タイミングをセットするコード 省略
}
const car_inspection = new CarInspection( '
[email protected]', '2024-11-03',
'2024-08-04')
if(car_inspection.isNotifyTiming()){
car_inspection.notify()
}
プロパティがnull
許可にならずに
すんでいる
if文の分岐になら
ずに済んでいる