This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseCommand<T> { | |
abstract parse(argv: string): T; | |
abstract run(config: T): void; | |
} | |
// parse と run の実装とインタフェースを矯正させる | |
class CommandA extends BaseCommand<{}> { | |
parse(argv: string) { | |
return {} | |
} | |
run(config: {}) { | |
} | |
} | |
type CommandBConfig = {hoge:number} | |
class CommandB extends BaseCommand<CommandBConfig> { | |
parse(argv: string) { | |
return {hoge: 10} | |
} | |
run(config: CommandBConfig) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseCommand<T> { | |
abstract parse(argv: string): T; | |
abstract run(config: T): void; | |
initAndRun(argv: string) { | |
this.run(this.parse(argv)) | |
} | |
} | |
// parse と run の実装とインタフェースを矯正させて、initAndRun でまとめられる | |
class CommandA extends BaseCommand<{}> { | |
parse(argv: string) { | |
return {} | |
} | |
run(config: {}) { | |
} | |
} | |
type CommandBConfig = {hoge:number} | |
class CommandB extends BaseCommand<CommandBConfig> { | |
parse(argv: string) { | |
return {hoge: 10} | |
} | |
run(config: CommandBConfig) { | |
} | |
} |
sonatard
commented
Jan 22, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment