Last active
January 22, 2021 12:52
-
-
Save odanado/12a7708779396f05f51c9360c688343f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hidden or 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) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.