Skip to content

Instantly share code, notes, and snippets.

@jeftarmascarenhas
Created August 19, 2021 17:06
Show Gist options
  • Save jeftarmascarenhas/7750f70786fa0a70dcbfea828d424f39 to your computer and use it in GitHub Desktop.
Save jeftarmascarenhas/7750f70786fa0a70dcbfea828d424f39 to your computer and use it in GitHub Desktop.
Refactoring Extract Method(Solution 1)
class LongMethod {
description: string = 'I need Refactoring'
printBanner(): void {
console.log('printBanner')
}
getOutMethod(): string {
return 'getOutMethod'
}
printOwing(): void {
this.printBanner()
// Print details
console.log(`description: ${this.description}`)
console.log(`amout: ${this.getOutMethod()}`)
}
}
const longMethodExample = new LongMethod()
console.log('Long Method \n')
longMethodExample.printOwing()
class ExtractMethod {
description: string = 'I was refactored, thanks god!'
printBanner(): void {
console.log('printBanner')
}
getOutMethod(): string {
return 'getOutMethod'
}
// Refactoring...
printOwing(): void {
this.printBanner()
this.printDetails()
}
printDetails(): void {
console.log(`description: ${this.description}`)
console.log(`amout: ${this.getOutMethod()}`)
}
}
const extractMethodExample = new ExtractMethod()
console.log('Extract Method \n')
extractMethodExample.printOwing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment