Skip to content

Instantly share code, notes, and snippets.

@Arsenalist
Created April 4, 2019 20:11
Show Gist options
  • Save Arsenalist/e7d25b074206b529289847357b557d12 to your computer and use it in GitHub Desktop.
Save Arsenalist/e7d25b074206b529289847357b557d12 to your computer and use it in GitHub Desktop.
Sample bad code
// EXAMPLE 1
class Appliance {
name: string;
constructor(name: string){
this.name = name;
}
getName() {
return this.name;
}
saveAppliance(a: Appliance) {
// some code to save the appliance
}
}
// EXAMPLE 2
class Washer extends Appliance { name: string = 'washer'}
class Dryer extends Appliance { name: string = 'dryer'}
class ApplianceRunner {
private appliance: Appliance;
constructor(appliance: Appliance) {
this.appliance = appliance;
}
run() {
if (this.appliance.name == 'washer') {
// Some code to wash
} else if (this.appliance.name == 'dryer') {
// some code to dry
}
}
}
// EXAMPLE 3
interface ApplianceContextListener {
onStart(a: Appliance): void;
onShutdown(a: Appliance): void;
}
// EXAMPLE 4
class ApplianceWarranty { }
class WasherWarranty extends ApplianceWarranty { }
class WarrantyValidator {
constructor(private washerWarranty: WasherWarranty) { }
isUnderWarranty(): boolean {
// We are a terrible company and want to randomly
// determine if an appliance is under warranty.
return Math.random() <= .5;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment