Created
June 25, 2018 06:27
-
-
Save achimoraites/58f139b2d7515fa9e43588da46b6106b to your computer and use it in GitHub Desktop.
Cohesion Types
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
class Example { | |
private ss: string; | |
constructor(s:string){ | |
this.ss = s; | |
} | |
// Functional Cohesion | |
parseString(s: string): string { | |
this.ss = s + "..."; | |
return this.ss; | |
} | |
// Sequential Cohesion | |
readString(s: string) { | |
let parsed = this.parseString(s); | |
let isValidated = this.validateString(parsed); | |
if(isValidated){ | |
console.log(parsed); | |
} | |
} | |
// Communicational / Informational Cohesion | |
validateString(s: string): boolean { | |
if (s.endsWith("...")) { | |
return this.executeFoo(s); | |
} else { | |
// do something else | |
return this.executeNonFoo(s); | |
} | |
} | |
// Procedural Cohesion | |
resetString(){ | |
// check if valid | |
let valid = this.validateString(this.ss); | |
if(valid){ | |
this.ss.replace("...",""); | |
} | |
} | |
// "Helpers" | |
executeFoo(s:string):boolean{ | |
return true; | |
} | |
executeNonFoo(s:string):boolean{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment